I'm trying to add up all VM's in my environment and outputting to HTML for a report. What you thought would be a simple task turns out not to be so easy.
Below works correctly in outputting the all the VM's
$vms = get-vm
$vmsCount = $vms.Count
Below works correctly in outputting the all the VM's
$vms = get-vm
$vmsCount = $vms.Count | ConvertTo-Html -as Table -Fragment | Out-String
calling $vmsCount returns an empty table like so:
<table>
</table>
any ideas?
Just in case someone else comes across an issue like this i was able to resolve it like so:
$GetAllHosts = Get-VMHost
$getHostsCount = $GetAllHosts.count
$GetAllVms = Get-VM
$GetVmsCount = $GetAllVms.count
$outObj = New-Object -TypeName PSObject
Add-Member -InputObject $outObj -MemberType NoteProperty `
-Name VMCount -Value $GetVmsCount
Add-Member -InputObject $outObj -MemberType NoteProperty `
-Name VMHostCount -Value $getHostsCount
$VmsAndHosts = $outObj | Select VMCount, VMHostCount | ConvertTo-Html -As:LIST -Fragment -PreContent '<h3>Total Hosts and VMs</h3>' | Out-String
Just in case someone else comes across an issue like this i was able to resolve it like so:
$GetAllHosts = Get-VMHost
$getHostsCount = $GetAllHosts.count
$GetAllVms = Get-VM
$GetVmsCount = $GetAllVms.count
$outObj = New-Object -TypeName PSObject
Add-Member -InputObject $outObj -MemberType NoteProperty `
-Name VMCount -Value $GetVmsCount
Add-Member -InputObject $outObj -MemberType NoteProperty `
-Name VMHostCount -Value $getHostsCount
$VmsAndHosts = $outObj | Select VMCount, VMHostCount | ConvertTo-Html -As:LIST -Fragment -PreContent '<h3>Total Hosts and VMs</h3>' | Out-String