Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 179681

PowerCLI Script to Gather VM Guest Network Information Using get-view

$
0
0

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


Viewing all articles
Browse latest Browse all 179681

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>