I need small help , in converting normal string to html format using convertto-enhancedhtml
Below is a sample code I am using. I want to output couple of variables in html page for multiple servers but I am not able to do that. What change do I need to make in the code.
I am getting the output in desired format but instead of the variables I get length value of the string.
I am able to get the desired output using convertto-html ,but I want to use convertto-enhancedHTMLFragments for the same piece of code, so that I can highlight cells that do not meet the condition and this can happen only if I use EnhancedHTMLFragments.
$server = ‘wdcqvap21’
foreach ($computer in $server){
$frag1 = ConvertTo-Html -as list -PreContent "Parameter file has been renamed for $server" | out-string
$frag2 = ConvertTo-html -as List -PreContent "Parameter file has been amended for $server" | Out-String
ConvertTo-HTML -head $css -body "$computer",$frag1,$frag2 | Out-File "c:\temp\syz.html"
}
There’s no need to include the variables in quotation marks.
But, more specifically:
[String]$a2 = Write-Output "Parameter file has been ammended for $computer !!"
$frag2 = $A2 | ConvertTo-EnhancedHTMLFragment -as list | Out-String
The EnhancedHTML commands are expecting objects as input. They’re designed to enumerate the object’s properties to construct a list or table. You’re passing in a string, which has a Length property, and so that’s what you’re getting. The commands weren’t designed to just display simple messages like this. You’re also going through a real unnecessary set of steps.
$a2 = "Parameter file has been ammended for $computer !!"
Is sufficient, and you can use $a2 in the fragment list for ConvertTo-EnhancedHTML.