VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Getting Blank Output without any Error

Hi,

I am trying to get the VMs which has more than 1 NIC card with its detailed info. I tried using below and getting blank output.

Please help!!

Get-VM -PipelineVariable vm | Get-NetworkAdapter | Where-Object {$_.Parent.NetworkAdapters.Count -gt 1} |
Select @{N='Folder';E={$vm.Folder}},
@{N='VM';E={$vm.Name}},
@{N="VM PowerState";E={($vm.PowerState)}},
@{N="Operating System"; E={@($vm.guest.OSFullName)}},
@{N='NW_Name';E={$_.Name}},
@{N="Port Group"; E={$_.NetworkName}},
@{N="IP Address";E={$nic = $_; ($vm.Guest.Nics | where{$_.Device.Name -eq $nic.Name}).IPAddress -join '|'}},
@{N='MAC_Address';E={$_.MacAddress}},
@{N='MAC_Model';E={$_.Type}},
@{N='MAC_Mode';E={$_.extensiondata.AddressType}},
@{N='Connected';E={$_.extensiondata.Connectable.Connected}},
@{N='Status';E={$_.extensiondata.Connectable.Status}} | ft -auto

 

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

There is no NetworkAdapters property on the VM object.

You could do any of the following.

No VMware Tools installed or VM powered off.

Get-VM -PipelineVariable vm |
Where-Object { ($vm.ExtensionData.Config.Hardware.Device.where{ $_ -is [VMware.Vim.VirtualEthernetCard] }).Count -gt 1 } |
Get-NetworkAdapter |
Select @{N='Folder';E={$vm.Folder}},
@{N='VM';E={$vm.Name}},
@{N="VM PowerState";E={($vm.PowerState)}},
@{N="Operating System"; E={@($vm.guest.OSFullName)}},
@{N='NW_Name';E={$_.Name}},
@{N="Port Group"; E={$_.NetworkName}},
@{N="IP Address";E={$nic = $_; ($vm.Guest.Nics | where{$_.Device.Name -eq $nic.Name}).IPAddress -join '|'}},
@{N='MAC_Address';E={$_.MacAddress}},
@{N='MAC_Model';E={$_.Type}},
@{N='MAC_Mode';E={$_.extensiondata.AddressType}},
@{N='Connected';E={$_.extensiondata.Connectable.Connected}},
@{N='Status';E={$_.extensiondata.Connectable.Status}} | ft -auto


With VMware Tools installed and the VM is powered on.

Get-VM -PipelineVariable vm |
Where-Object { $_.Guest.Nics.Count -gt 1 } |
Get-NetworkAdapter |
Select @{N='Folder';E={$vm.Folder}},
@{N='VM';E={$vm.Name}},
@{N="VM PowerState";E={($vm.PowerState)}},
@{N="Operating System"; E={@($vm.guest.OSFullName)}},
@{N='NW_Name';E={$_.Name}},
@{N="Port Group"; E={$_.NetworkName}},
@{N="IP Address";E={$nic = $_; ($vm.Guest.Nics | where{$_.Device.Name -eq $nic.Name}).IPAddress -join '|'}},
@{N='MAC_Address';E={$_.MacAddress}},
@{N='MAC_Model';E={$_.Type}},
@{N='MAC_Mode';E={$_.extensiondata.AddressType}},
@{N='Connected';E={$_.extensiondata.Connectable.Connected}},
@{N='Status';E={$_.extensiondata.Connectable.Status}} | ft -auto




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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

There is no NetworkAdapters property on the VM object.

You could do any of the following.

No VMware Tools installed or VM powered off.

Get-VM -PipelineVariable vm |
Where-Object { ($vm.ExtensionData.Config.Hardware.Device.where{ $_ -is [VMware.Vim.VirtualEthernetCard] }).Count -gt 1 } |
Get-NetworkAdapter |
Select @{N='Folder';E={$vm.Folder}},
@{N='VM';E={$vm.Name}},
@{N="VM PowerState";E={($vm.PowerState)}},
@{N="Operating System"; E={@($vm.guest.OSFullName)}},
@{N='NW_Name';E={$_.Name}},
@{N="Port Group"; E={$_.NetworkName}},
@{N="IP Address";E={$nic = $_; ($vm.Guest.Nics | where{$_.Device.Name -eq $nic.Name}).IPAddress -join '|'}},
@{N='MAC_Address';E={$_.MacAddress}},
@{N='MAC_Model';E={$_.Type}},
@{N='MAC_Mode';E={$_.extensiondata.AddressType}},
@{N='Connected';E={$_.extensiondata.Connectable.Connected}},
@{N='Status';E={$_.extensiondata.Connectable.Status}} | ft -auto


With VMware Tools installed and the VM is powered on.

Get-VM -PipelineVariable vm |
Where-Object { $_.Guest.Nics.Count -gt 1 } |
Get-NetworkAdapter |
Select @{N='Folder';E={$vm.Folder}},
@{N='VM';E={$vm.Name}},
@{N="VM PowerState";E={($vm.PowerState)}},
@{N="Operating System"; E={@($vm.guest.OSFullName)}},
@{N='NW_Name';E={$_.Name}},
@{N="Port Group"; E={$_.NetworkName}},
@{N="IP Address";E={$nic = $_; ($vm.Guest.Nics | where{$_.Device.Name -eq $nic.Name}).IPAddress -join '|'}},
@{N='MAC_Address';E={$_.MacAddress}},
@{N='MAC_Model';E={$_.Type}},
@{N='MAC_Mode';E={$_.extensiondata.AddressType}},
@{N='Connected';E={$_.extensiondata.Connectable.Connected}},
@{N='Status';E={$_.extensiondata.Connectable.Status}} | ft -auto




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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I tried the below one, this is showing all the VMs which has more than 1 nic along with VMs which dont have more than 1 nic.

Get-VM -PipelineVariable vm |
Where-Object { $_.Guest.Nics.Count -gt 1 } |
Get-NetworkAdapter |
Select @{N='Folder';E={$vm.Folder}},
@{N='VM';E={$vm.Name}},
@{N="VM PowerState";E={($vm.PowerState)}},
@{N="Operating System"; E={@($vm.guest.OSFullName)}},
@{N='NW_Name';E={$_.Name}},
@{N="Port Group"; E={$_.NetworkName}},
@{N="IP Address";E={$nic = $_; ($vm.Guest.Nics | where{$_.Device.Name -eq $nic.Name}).IPAddress -join '|'}},
@{N='MAC_Address';E={$_.MacAddress}},
@{N='MAC_Model';E={$_.Type}},
@{N='MAC_Mode';E={$_.extensiondata.AddressType}},
@{N='Connected';E={$_.extensiondata.Connectable.Connected}},
@{N='Status';E={$_.extensiondata.Connectable.Status}} | ft -auto

 

 

Tags (1)
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I see a couple of those as well.
In my case that is caused by the Guest OS having one or more "ghost" network adapters.

The other option, based on ExtensionData.Config.Hardware is what vSphere sees, not what the Guest OS shows.


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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Now I got it. Thank you very much LucD 🙂

 

Reply
0 Kudos