Problem:
How do I see which port groups my VMs are in?
Solution:
Run the below PowerShell code:
Connect-VIServer servername -User -Password Get-VM | Select Name,PowerState,Version,NumCPU,MemoryGB,ProvisionedSpaceGB,UsedSpaceGB, @{N='GuestOS';E={$_.Guest.OSFUllName}}, @{N='PortgroupName';E={(Get-NetworkAdapter -VM $_).NetworkName -join '|'}}, @{N='PortgroupVlanId';E={(Get-VirtualPortGroup -Name (Get-NetworkAdapter -VM $_).NetworkName -VMHost $_.VMHost).VlanId -join '|'}}, @{N='Cluster';E={(Get-Cluster -VM $_).Name}}, @{N='HostName';E={$_.VMHost.Name}} | Export-Csv C:\temp\VMPortGroup.csv