I am having hard time to understand how to get this to work.
I already have a script that creates a report using a custom CSS and using “ConvertTo-HTML” from some cmdlets I use, this works fine.
Now I have a new script I wrote, an I am trying to create the same HTML table but this time I only want to use some variables from my script to add them into a table using two columns.
I tried to put the vars into a hash table and convert it to HTML - not working.
I tried to create a PSObject and convert it to HTML - not working.
I would appreciate if someone here would please give some advise how to change this code and create a 2 column table that contains the name,value of the hash table or otherwise use only the variables created (maybe by using a PSObject?)
Snippet from the script:
$Css='table{margin:auto; width:98%} Body{background-color:LightSteelBlue; Text-align:Center;} th{border-width: 1px;padding: 0px;border-style: solid;border-color: black; background-color:black; color:white;} td{border-width: 1px;padding: 0px;border-style: solid;border-color: black; background-color: #D3D3D3; color:Black; Text-align:Center;} ' $Report = '' $Report += '' $Report += "`n`t" $Report += $Css # Fiddle with browser mode $Report += "`n" + '' #'' $Report += "`n`t`n`n" $Report += "PowerShell Audit ReportThis report was generated @: $(Get-Date)==========================================" ## Variables $FName = 'Bila' $LName = 'Bong' $Age = '120' ## Create a table $Hash = @{"FName" = $FName ; "LName" = $LName ; "Age" = $Age} $Table = $Hash | ConvertTo-Html -Fragment -As Table | Out-String $Report += "$Table " $Report += "===== DONE >=====" $Report +="" $Report += "`n`n" # R debug #$Report += "document.body.innerHTML += navigator.userAgent.toLowerCase();" $Report | Out-File $PWD\test.htm ; Invoke-Expression $PWD\test.htm