VMware Cloud Community
edelldieguez
Contributor
Contributor

Gettting all Networkt Adapter info from all our VMs

Hi Guys,

I'm playing with this script trying to get all the network info from our VMs, i can find that info but from one vm at a time, can i have something to get that info from all my VMs in the cluster ??

Here the script: Get-NetworkAdapter -VM "VM_NAME"

Thanks in advance.

0 Kudos
9 Replies
RvdNieuwendijk
Leadership
Leadership

You can get the network adapters of all VM's with:

Get-VM | Get-NetworkAdapter | Select-Object -Property *

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
LucD
Leadership
Leadership

For all VMs in a cluster, you can do

Get-Cluster -Name MyCluster | Get-VM | Get-NetworkAdapter


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

edelldieguez
Contributor
Contributor

Hi Guys,

Thanks for your reply.

Any way to modify the script to get this info and exported to a .csv format?, few VMs in our cluster have more than one NIC card.

VM NameNIC Name : NIC Type : Network Name : Connection State : MAC Address : WakeOnLine Enable

Thanks in advance LucD and Robert.

0 Kudos
RvdNieuwendijk
Leadership
Leadership

The next script lists the required properties of the network adapters of all VM's of cluster MyCluster to a csv file called NetworkAdapters.csv.

Get-Cluster -Name MyCluster | Get-VM | 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="WakeOnLan Enabled";E={$_.WakeOnLanEnabled}} | `
Export-Csv -Path NetworkAdapters.csv -NoTypeInformation -UseCulture

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
edelldieguez
Contributor
Contributor

Thanks guys, exactly what I was looking for.

Thanks.

0 Kudos
mark_chuman
Hot Shot
Hot Shot

The virtual machine names aren't coming through for me on this one:

"VM Name","NIC Name","MAC Address"

,"Network adapter 1","00:50:56:99:78:53"

,"Network adapter 1","00:50:56:81:0d:b2"

Script:

Get-VM | Get-NetworkAdapter | `
Select-Object -Property `
@{N="VM Name";E={$_.Parent}},
@{N="NIC Name";E={$_.Name}},
@{N="MAC Address";E={$_.MacAddress}} | `
Export-Csv -Path NetworkAdapters.csv -NoTypeInformation -UseCulture

(I didn't need the extra info and needed it for each VM under the VC, so altered the script a bit).

0 Kudos
LucD
Leadership
Leadership

Check your PowerCLI version.

Do a

Get-PowerCLIVersion


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

0 Kudos
mark_chuman
Hot Shot
Hot Shot

Looks like 4.0, U1.

PowerCLI Version
----------------
VMware vSphere PowerCLI 4.0 U1 build 208462

I read the installation guides for newer versions of PowerCLI and saw this, which conflicts with some of our environment (Some ESX still at 3.5, U4).

vSphere PowerCLI is compatible with the following VMware environments:

vSphere PowerCLI is compatible with the following VMware environments:
 VMware ESX 4.1/vCenter Server 4.1
 VMware ESXi 4.1
 VMware ESX 4.0 Update 1/vCenter Server 4.0 Update 1
 VMware ESXi 4.0 Update 1
 VMware ESX 3.5 Update 5
 VMware ESXi 3.5 Update 5

We have VC 4.1 managing ESX (3.5U4,4.0U1)

0 Kudos
LucD
Leadership
Leadership

I replied in your other thread.


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

0 Kudos