Before I start, let me say that I get the results that I want when I output the results to a text file.
I am trying the run the code below, and I will explain what I am trying to do. I am filtering for VMs by the Guest OS Name (XP, 2003, etc). I only wanted to list the name, powerstate, and guest OS. I know the code is is all over the place, I was playing with certain sections to get them to work.
$OS2008 = Get-VM | where { $_.guest.OSFullname -match "2008" } | Select @{N="VMname"; E={ $_.name }}, @{ N="Something"; E={ $_.Powerstate } }, @{ N="OS"; E={ $_.guest.OSFullName } } #$_.Name, $_.guest.OSFullname, $_.Powerstate #| foreach { $_.Name, $_.guest.OSFullname, $_.Powerstate, "---------" };
$OSCount2008 = (Get-VM | where { $_.guest.OSFullname -match "2008" }).count
$line = "===================================================================================================================================================="
$custom = '<style>
BODY{background-color:#999966;}
TABLE{border-width:1px; border-style:solid; border-color:black; border-collapse:collapse;}
TH{border-width:1px; padding:0px; border-style:solid; border-color:black;}
TD{border-width:1px; padding:0px; border-style:solid; border-color:black;}
</style>'
$OS2008 + $OSCount2008 | ConvertTo-Html -Head $custom -Body '<H2>OS Count</H2>' | Out-File c:\PSresults\TestOSCount.htm
If ran right now, I will get a nice html page with 3 Columns and however many rows there are to fill out the VM names. I have a few problems....the first thing is that this is just a portion of what I was writing. I have variables for XP, 2003, 2008, Vista, Linux and Other. As you can see I also have a variable to count the number of VMs for whichever OS I filter for.
When I ran everything and Out-File it to a text, it comes out nice, but I like the way an HTML file looks, so I used formatting that I saw on technet and that I use for a Snapshot script and I added (+) everything together. The text file comes out just the way that I want, It has the properties that I want, then the count of the machines underneath, and then I write out a bunch of equal signs =========== so the next section is easily visible. The code that I use for the text file is Bold and in Burgundy at the bottom of the page. When I tried that with the my formatting and the ConvertTo-HTML command, I received a bunch of numbers, so I played with it so that I can at least see some legible output.
My main problem now is that when I add two variables together and output to HTML I don't get anything except for the first variable. So When I add $OS2008 + $OSCount2008 the HTML page only shows $OS2008. I also tried to create a new vaiable $something = $OS2008 + $OSCount2008 and then I would try to only output that "$something" variable, but it still would not work. If I typed out the variable, I will see what I wanted, it just would not display correctly with the HTML.
I have been going on long enough, I hope I am making sense, I realize I'm all over the place. Thanks for any help.
$OS2008 = Get-VM | where { $_.guest.OSFullname -match "2008" } | foreach { $_.Name, $_.guest.OSFullname, $_.Powerstate, "---------" };
$OSCount2008 = Get-VM | where { $_.guest.OSFullname -match "2008" } | measure
$OS2003 = Get-VM | where { $_.guest.OSFullname -match "2003" } | foreach { $_.Name, $_.guest.OSFullname, $_.Powerstate, "---------" };
$OSCount2003 = Get-VM | where { $_.guest.OSFullname -match "2003" } | measure
$OSXP = Get-VM | where { $_.guest.OSFullname -match "XP" } | foreach { $_.Name, $_.guest.OSFullname, $_.Powerstate, "---------" };
$OSCountXP = Get-VM | where { $_.guest.OSFullname -match "XP" } | measure
$OSVista = Get-VM | where { $_.guest.OSFullname -match "Vista" } | foreach { $_.Name, $_.guest.OSFullname, $_.Powerstate, "---------" };
$OSCountVista = Get-VM | where { $_.guest.OSFullname -match "Vista" } | measure
$OS7 = Get-VM | where { $_.guest.OSFullname -match "7" } | foreach { $_.Name, $_.guest.OSFullname, $_.Powerstate, "---------" };
$OSCount7 = Get-VM | where { $_.guest.OSFullname -match "7" } | measure
$OSLinux = Get-VM | where { $_.guest.OSFullname -match "Linux" } | foreach { $_.Name, $_.guest.OSFullname, $_.Powerstate, "---------" };
$OSCountLinux = Get-VM | where { $_.guest.OSFullname -match "Linux" } | measure
$OSOther = Get-VM | where { $_.guest.OSFullname -notmatch "2008" -and $_.guest.OSFullName -notmatch "XP" -and $_.guest.OSFullName -notmatch "7" -and $_.guest.OSFullName -notmatch "2003" -and $_.guest.OSFullName -notmatch "Linux"}`
| foreach { $_.Name, $_.guest.OSFullname, $_.Powerstate, "---------" };
$OSCountOther = Get-VM | where { $_.guest.OSFullname -notmatch "2008" -and $_.guest.OSFullName -notmatch "XP" -and $_.guest.OSFullName -notmatch "7" -and $_.guest.OSFullName -notmatch "2003" -and $_.guest.OSFullName -notmatch "Linux"} | measure
$line = "===================================================================================================================================================="
$OS2008 + $OSCount2008 + $line + $OS2003 + $OSCount2003 + $line + $OSXP + $OSCountXP + $line + $OSVista + $OSCountVista + $line + $OS7 + $OSCount7 + $line + $OSLinux + $OSCountLinux + $line + $OSOther + $OSCountOther |`
Out-File c:\PSresults\AllOSCount.txt