VMware Cloud Community
CenturaBro
Enthusiast
Enthusiast
Jump to solution

Adding up all VM's in an environment and converting to HTML

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?

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
CenturaBro
Enthusiast
Enthusiast
Jump to solution

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

View solution in original post

Reply
0 Kudos
1 Reply
CenturaBro
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos