I want to combine output of the Get-VM and Measure-VM cmdlets into single HTML table with some columns of Get-VM and Measure-VM.
I want the columns VMName, State, RAM, DISK.
Get-VM gives me VMName and State and Measure-VM gives me RAM and DISk.
So I want to combine these four columns into a single HTML table.
I have created code as below.
Get-VM –ComputerName $hostnm |
Select-Object Name, State, Uptime,
@{Name="RAM In GB";Expression={[Math]::Round($_.MemoryAssigned/1GB, 2)}} |
ConvertTo-Html -Head $a
Measure-VM –Name * -Computername $hostnm |
Sort-Object VMName |
Select-Object VMName,
@{Name="RAM In GB";Expression={[Math]::Round($_.MaxRAM/1024, 2)}},
@{Name="Disk Size in GB";Expression={[Math]::Round($_.TotalDisk/1024, 2)}} |
ConvertTo-Html -Head $a
So how do I combine this?
$vmhost = Get-Content C:\Users\Share1\Desktop\Scripts\VMHosts.txt
$file = "C:\Users\Share1\Desktop\Scripts\output.htm"
$report = "<html> <body>"
$a = "<style>"
$a = $a + "body {font-family: Tahoma; background-color:#fff;}"
$a = $a + "table {font-family: Tahoma;width: $($rptWidth)px;font-size: 12px;border-collapse:collapse;}"
$a = $a + "th {background-color: #cccc99;border: 1px solid #a7a9ac;border-bottom: none;}"
$a = $a + "td {background-color: #ffffff;border: 1px solid #a7a9ac;padding: 2px 3px 2px 3px;vertical-align: middle;text-align:center;}"
$a = $a + "</style>"
$op1 = @()
$op2 = @()
$myresult = @()
$output = foreach ($hostnm in $vmhost) {
Enable-VMResourceMetering -Name $hostnm -ResourcePoolType @("Processor","VHD","Ethernet","Memory")
echo "--------------------</br>"
echo "<b>" $hostnm "</b></br>"
echo "--------------------</br>"
$op1 = Get-VM –ComputerName $hostnm |
Select-Object Name, State, Uptime,
@{Name="RAM In GB"; Expression={[Math]::Round($_.MemoryAssigned/1GB, 2)}} |
ConvertTo-Html -Head $a
Get-VM –Name * -ComputerName $hostnm | Enable-VMResourceMetering
$op2 = Measure-VM –Name * -ComputerName $hostnm |
Sort-Object VMName |
Select-Object VMName,
@{Name="RAM In GB";Expression={[Math]::Round($_.MaxRAM/1024, 2)}},
@{Name="Disk Size in GB";Expression={[Math]::Round($_.TotalDisk/1024, 2)}} |
ConvertTo-Html -Head $a
$myresult = $op1 + $op2
}
$report = $report + $output + $myresult + "</body></html>"
$report | Out-File $file
Actual result is I am getting two different tables of Get-VM and Measure-VM.
Expected result is only one table which has VM Name, State, RAM in GB, Disk in GB.