Saaspowc
Contributor
Contributor

Script to export Muitlple IP Address and its subnet, VLAN and gateway information

Jump to solution

Hi,

Looking for a script to capture multiple IP address and its subnet mask, Gateway, VLAN information for more than 1000 VMs from vCenter server. I'm not sure how to get Get-VM into loop to obtain multiple IP address, subnet, VLAN, gateway to export to CSV file.

Could you please point me the correct syntax for this. Thanks in advance.

0 Kudos
1 Solution

Accepted Solutions
vin01
Expert
Expert
0 Kudos
3 Replies
LucD
Leadership
Leadership

To get the IP addresses, provided there are multiple in a guest OS, in 1 property, you could do something like this

Get-VM |

Select Name,@{N='IP';E={[string]::Join(',',$_.Guest.IPAddress)}}

To get a separate row per IP address, you could do

foreach($vm in Get-VM){

    $vm.Guest.IPAddress |

    Select @{N='Name';E={$vm.name}},@{N='IP';E={$_}}

}

Both of these methods require the VMware Tools to be installed and the VM to be powered on


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

vin01
Expert
Expert
0 Kudos
Saaspowc
Contributor
Contributor

Thanks LucD and Vineeth.

Vineeth - this is the information I'm looking for. Will run these and see what the output when running on VMs having multiple Nics.

0 Kudos