Automation

 View Only
  • 1.  Trying to count the number of NICs on VMs

    Posted Feb 10, 2010 10:48 AM

    Hi All

    Have been trying to create a script to simply count the number of NICs in a VM ?!? In all honesty havent a clue where to start ?!??! I do know there is a count 'property' but can't get to figure out how I can incorporate this into counting the Nics

    Thanks ALOT in advance

    Munster



  • 2.  RE: Trying to count the number of NICs on VMs

    Posted Feb 10, 2010 10:52 AM

    Try this

    (Get-Vm <VM-name>).NetworkAdapters.Count
    

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 3.  RE: Trying to count the number of NICs on VMs

    Posted Feb 10, 2010 10:53 AM

    Oops, seems my reply got submitted twice.



  • 4.  RE: Trying to count the number of NICs on VMs

    Posted Feb 10, 2010 11:07 AM

    Thanks LucD

    But my script seems to be a mess. Can you help please (NEWBIE I'm afraid)

    $vms = Get-VM

    foreach ($vm in $vms)

    {

    $vmNameExp = @{N = "VMName"; E = {$vm.name} }

    $vmNicCount = @{N = "VMNICCount"; E = {$vm.Networkadapters.count} }

    }

    Write-Host $vmNameExp, $vmNicCount

    I know I messed up - an you help please

    Munster



  • 5.  RE: Trying to count the number of NICs on VMs
    Best Answer

    Posted Feb 10, 2010 11:50 AM

    Try it this way

    $vms = Get-VM
    
    foreach ($vm in $vms) 
    {
    	$vm | Select @{N = "VMName"; E = {$vm.name} },
    		@{N = "VMNICCount"; E = {$vm.Networkadapters.count} }
    }
    

    Inside the foreach loop, you select from each $vm the Name and the NIC count.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 6.  RE: Trying to count the number of NICs on VMs

    Posted Jun 02, 2011 05:31 AM

    This works too:

    Get-VM | Select-Object -property name, @{name="nicCount"; expression = {$_.networkadapters.count}}

    And if you want to only list all VMs with more than 1 NIC:

    Get-VM | where-object {$_.networkadapters.count -gt 1} | Select-Object -property name, @{name="nicCount"; expression = {$_.networkadapters.count}}



  • 7.  RE: Trying to count the number of NICs on VMs

    Posted Dec 13, 2019 12:11 PM

    The solution by LucD didn't work for me, but I found this worked must faster than looping through a foreach. 

    New-VIProperty -Name NICs -ObjectType VirtualMachine -ValueFromExtensionProperty 'summary.Config.numEthernetcards'  -Force

    Get-VM