VMware Cloud Community
vcpguy
Expert
Expert

How to get the VM name and the associated nic card

Hi, I am trying to get the VM name and associated nic card type but I don't see the correct result. Can someone please look into it and tell me how to make it work. I am still new to Powershell

[vSphere PowerCLI] C:\> get-vm | Where-Object {$_.Networkadapters -eq "vmxnet3"}

The above cmd gives no output. I want it should list all the VM names and there NIC type.

Thanks

----------------------------------------------------------------------------- Please don't forget to reward Points for helpful hints; answers; suggestions. My blog: http://vmwaredevotee.com
0 Kudos
1 Reply
lockenkeyster
Enthusiast
Enthusiast

This should get you the info that you need:

Get-VM | Get-NetworkAdapter | foreach ($_) { Write-Host $_.Parent.Name "("$_.Name") type:" $_.Type }

But in larger environments it may be helpful to throw the info into a table that you can export later or look at one NIC at a time:

$myVMs = Get-VM
$allNics = @()
foreach ($vm in $myVMs) {
$myNics = Get-NetworkAdapter $vm
foreach ($nic in $myNics) {
$nicInfo = "" | Select "VM","Nic","NicType"
$nicInfo."VM" = $vm.Name
$nicInfo."Nic" = $nic.Name
$nicInfo."NicType" = $nic.Type
$allNics += $nicInfo
}
}
$allNics


0 Kudos