I have a script that uses convertToHtml, which all works fine, except it produces multiple table headers due to the way I'm looping through a list of server names. I'm trying to tidy this up if only the replace procedure would play nicely. Instead it seems to fail matching the string that I want to replace/ remove as it contains spaces.
I know that a -replace will use a reg-exp to match the string, but when trying a .replace I get a message saying that "[system.object[]] doesn't contain a method named 'replace'". I have tried entering the string as a reg exp string, which matches correctly when used with online regular expression testers.
I've already tried escaping the slashes & using \s where the spaces are, but still can't seem to get the string to match. I've also tried specifying that the $body variable is a string, but I can't seem to get this to work either.
Thanks in advance
I know that a -replace will use a reg-exp to match the string, but when trying a .replace I get a message saying that "[system.object[]] doesn't contain a method named 'replace'". I have tried entering the string as a reg exp string, which matches correctly when used with online regular expression testers.
Code:
#$stringtoreplace = " </table> <table> <colgroup> <col/> <col/> <col/> <col/> </colgroup> <tr><tr><th>MachineName</th><th>Name</th><th>DisplayName</th><th>Status</th></tr> <tr>"
$stringtoreplace = "\s<\/table>\s<table>\s<colgroup>\s<col\/>\s<col\/>\s<col\/>\s<col\/>\s<\/colgroup>\s<tr><tr><th>MachineName<\/th><th>Name<\/th><th>DisplayName<\/th><th>Status<\/th><\/tr>\s<tr>"
$body = $body -replace($stringtoreplace,"")
I've already tried escaping the slashes & using \s where the spaces are, but still can't seem to get the string to match. I've also tried specifying that the $body variable is a string, but I can't seem to get this to work either.
Thanks in advance