VMware Cloud Community
malek12
Contributor
Contributor

Need to Add IP addresses output to script (currently empty)

I am running the following script that gives me all the information I need except the IP address associated with the nics.  It is a specific set of VM's so I am just doing get-vm -name (list of names) and exporting to a csv file

Get-VM -Name (list of vm names) | Get-NetworkAdapter | `

Select-Object -Property `

@{N="VM Name";E={$_.Parent}},

@{N="NIC Name";E={$_.Name}},

@{N="NIC Type";E={$_.Type}},

@{N="Network Name";E={$_.NetworkName}},

@{N="Connection State";E={$_.ConnectionState}},

@{N="MAC Address";E={$_.MacAddress}},

@{N="IP Address";E={@($_.Guest.IPAddress)}},

@{N="WakeOnLan Enabled";E={$_.WakeOnLanEnabled}} | `

Export-Csv path to put output.

I get everything I need except the ip address.  Field is blank.  Can someone tell me what I should be using to collect the IP address info?

Thanks,

0 Kudos
4 Replies
LucD
Leadership
Leadership

Replace that line with

@{N="IP Address";E={$_.Parent.Guest.IPAddress -join '|'}},


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

0 Kudos
malek12
Contributor
Contributor

Thanks.  However, this gives me a list of the exact same IP addresses per network adapter.  So say I have adapter 1 and Adapter 2 and the IP information is the same for both even though they have different mac addresses?  Not sure if this is what is expected or if this has something to do with how the network in this environment is set up?  Or perhaps some OS networking I need to look into?  My expectation was that I would get a Network Adapter = mac address = the assigned IP for that network adapter.

I have attached an example that shows the network IP info as being the same for both network adapters with two different mac addresses

0 Kudos
LucD
Leadership
Leadership

Can you check if this version gives you a better result?

Get-VM |

Get-NetworkAdapter -PipelineVariable nic |

Select-Object -Property `

@{N="VM Name";E={$_.Parent}},

@{N="NIC Name";E={$_.Name}},

@{N="NIC Type";E={$_.Type}},

@{N="Network Name";E={$_.NetworkName}},

@{N="Connection State";E={$_.ConnectionState}},

@{N="MAC Address";E={$_.MacAddress}},

@{N="IP Address";E={($_.Parent.Guest.Nics | where{$_.MacAddress -eq $nic.MacAddress}).IPAddress -join '|'}},

@{N="WakeOnLan Enabled";E={$_.WakeOnLanEnabled}}


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

0 Kudos
malek12
Contributor
Contributor

This works and is more along the lines of what I was expecting.

Thanks LucD!

0 Kudos