Powershell –replace method and my own frustration.
Summary:
I added some code to my VMWare Infrastructure script for a new column of data to show a tooltip when clicked or hovered over. Because I also have it export a csv file from this code, I use the –replace method to strip the html formatting. Because of one section, more data than I wanted was being stripped. Why? Probably because I used this: .*> .
Resolution:
Anyway here is the string I was using:
And here is how I fixed it:
Simply by moving one replace statement w/ the .*> to the end of the chain solved my problem. I still don’t quite understand, but whatever, some other time and place.
Side note:
I think I’m going to make separate properties in my report object for RAW data, add html formatted versions to other properties, and use Select statements for export to avoid this conundrum altogether.
I added some code to my VMWare Infrastructure script for a new column of data to show a tooltip when clicked or hovered over. Because I also have it export a csv file from this code, I use the –replace method to strip the html formatting. Because of one section, more data than I wanted was being stripped. Why? Probably because I used this: .*> .
Resolution:
Anyway here is the string I was using:
1: foreach {$_ -replace("<p style='font-weight:bold;color:orange'>","") -replace("<p style='font-weight:bold;color:red'>","") -replace("<a class='cluster' href=./healthcheck.htm#.*> ","") -replace("</p>","") -replace ("</a>","") -replace ("<a href='#' class='tt'>","") -replace ("<span class='tooltip'><span class='top'></span><span class='middle'>Digi says... <br />.*","") -replace ("</span><span class='bottom'></span></span>","") }|
And here is how I fixed it:
1: foreach {$_ -replace("<p style='font-weight:bold;color:orange'>","") -replace("<p style='font-weight:bold;color:red'>","") -replace("</p>","") -replace ("</a>","") -replace ("<a href='#' class='tt'>","") -replace ("<span class='tooltip'><span class='top'></span><span class='middle'>Digi says... <br />.*","") -replace ("</span><span class='bottom'></span></span>","") -replace("<a class='cluster' href=./healthcheck.htm#.*> ","")}
Simply by moving one replace statement w/ the .*> to the end of the chain solved my problem. I still don’t quite understand, but whatever, some other time and place.
Side note:
I think I’m going to make separate properties in my report object for RAW data, add html formatted versions to other properties, and use Select statements for export to avoid this conundrum altogether.
Comments