Just can't get this to work right. Name, IP, MacAddress, VlanID, and Network Adapter are fine but Gateway, SubnetMask, and DNS are all blanks. Any help would be appreciated.
Get-View -ViewType VirtualMachine -Filter @{'Runtime.PowerState'='poweredOn'} |
Select Name,
@{N='IPAddress';E={$_.Guest.ipAddress}},
@{N='Gateway';E={$nicInfo = Get-VMGuestNetworkInterface -VM $_ [string]::Join(',',($nicInfo | Select -ExpandProperty DefaultGateway))}},
@{N='SubnetMask';E={[string]::Join(‘,’,($subnetmask))}},
@{N='DNS';E={[string]::Join(',',($vm.ExtensionData.Guest.IpStack.DnsConfig.IpAddress))}},
@{N='MacAddress';E={($_.Config.Hardware.Device | where{$_ -is [VMware.Vim.VirtualEthernetCard]}).MacAddress -join '|'}},
@{N='VlanId';E={$folder = Get-Folder VM
$folderView = Get-View $folder -Property "[VirtualMachine]ChildEntity.Network.*"
$folderView.LinkedView.ChildEntity[0].LinkedView.Network | Select-Object -ExpandProperty Name}},
@{N='Network Adapter';E={$_.Config.Hardware.Device | Where {$_ -is [VMware.Vim.VirtualEthernetCard]} | ForEach {$_.GetType().Name.Replace('Virtual','')}}} | Out-GridView