$VMs = get-VM
$Report = @()
Foreach ($VM in $VMs) {
$NewObj = "" | Select VMName, CPU, Memory, DiskSize, GuestOS, PGName, VLANID, Cluster, HostName
$NewObj.VMName = $VM.Name
$NewObj.CPU = $VM.NumCPU
$NewObj.Memory = $VM.MemoryGB # Or swap out w/ $VM.MemoryMB if you want
$NewObj.DiskSize = $VM.ProvisionedSpaceGB # If you want just used $VM.UsedSpaceGB
$PG = $VM | Get-VirtualPortGroup
If ($PG.count -gt 1)
{
$PortGroups = $null
$VLANIDs = $null
Foreach ($Portgroup in $PG)
{
$PortGroups = $Portgroup.Name + " | " + $PortGroups
$VLANIDs = $Portgroup.VLANID + " | " + $VLANIDs
}
$NewObj.PGName = $PortGroups.trimend("|")
$NewObj.VLANIDs = $VLANIDs.trimend("|")
}
Else {
$NewObj.PGName = $PG.Name
$NewObj.VLANID = $PG.VLANID
}
$NewObj.GuestOS = $VM.Guestid
$NewObj.Cluster = $VM.vmhost.parent.name
$NewObj.hostname = $VM.vmhost.name
$Report += $NewObj
}
$Report