I'm trying to convert a report to HTML, and I just can't seem to understand when I need to convert these objects. I know the basic ConvertTo-HTML cmdlet, and I've posted up questions before and received answers, but it always turns out that something new comes up, and it's usually a different problem.
This is a short version of a script I’m writing, I’m trying to keep it simple for myself, so that I can understand and look at the data that is being converted. Since my report is going to have the VMname, and OS, I want an HTML document with the table columns as VMname, and OS, and then the row will have the data right below the column. I’ve looked online at many examples online, but I can’t seem to find something for my situation. I’ve seen the use of ConvertTo-HTML -fragment, and other examples, but it does not work out the way I want.
How would the script below produce what I’m asking for? If I can get these 2 items, then I feel that I can use that example and finish the rest of the script.
Thanks in advance.
$custom = "<style>
body {background-color: lightblue; }
table {background-color: white; margin: 5px; float: left; top: 0px; display: inline-block; padding: 5px; border: 1px solid black }
tr:nth-child(odd) {background-color: lightgray}
</style>"
$AllReport = $null
$AllReport = @()
Get-Folder Folder | Get-VM | foreach {
$VMlist = $_
$Report = "" | Select VMname, OS
$Report.VMname = $VMlist.name
$Report.OS = $VMlist.guest.OSFullname
$AllReport += $Report
#$AllReport | ConvertTo-Html -As Table -Head $custom
#$AllReport | Out-File c:\Output\HTMLout.htm
}
#$HTML | Out-File c:\output\testhtm.html
#ii c:\Output\testhtm.html
Try like this
$custom = @"
<style>
body {background-color: lightblue; }
table {background-color: white; margin: 5px; float: left; top: 0px; display: inline-block; padding: 5px; border: 1px solid black }
tr:nth-child(odd) {background-color: lightgray}
</style>
"@
$AllReport = $null
$AllReport = @()
Get-Folder Folder | Get-VM | foreach {
$VMlist = $_
$Report = "" | Select VMname, OS
$Report.VMname = $VMlist.name
$Report.OS = $VMlist.guest.OSFullname
$AllReport += $Report
}
$AllReport | ConvertTo-Html -As Table -Head $custom |
Out-File htmltest.htm
Invoke-Item htmltest.htm
The basic concept for producing HTML output is in essence quite simple:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Like always, thanks a million. It's always much easier than I think it is. I was doing way too much. Everything is working, thanks again, and I can't wait for the new PowerCLI book from you...good luck with that.