VMware Cloud Community
bradleyjs
Contributor
Contributor
Jump to solution

Get the number of VMkernel Ports on a vDS

I've searched and just can't find the snippet of code to read the count of VMkernel Ports on distributed switch.

Anyone got a snippet?

Reply
0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

The following PowerCLI command will give you a list of the number of VMKernel ports for all of your distributed switches:

Get-VDSwitch | Select-Object -property Name,

@{Name='Number of VMKernel ports';Expression={($_ | Get-VMHostNetworkAdapter | Where-Object {$_.DeviceName -like 'vmk*'} | Measure-Object).Count}}

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

View solution in original post

Reply
0 Kudos
2 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

The following PowerCLI command will give you a list of the number of VMKernel ports for all of your distributed switches:

Get-VDSwitch | Select-Object -property Name,

@{Name='Number of VMKernel ports';Expression={($_ | Get-VMHostNetworkAdapter | Where-Object {$_.DeviceName -like 'vmk*'} | Measure-Object).Count}}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
bradleyjs
Contributor
Contributor
Jump to solution

Thanks RvdNieuwendijk - you put me on the right track with your sample code.


This is what I came up with:

       $NumVMkPorts = (Get-VMHostNetworkAdapter -DistributedSwitch $PG.VDSwitch.Name | Where-Object {$_.DeviceName -like 'vmk*' -and $_.PortGroupName -eq $PG.Name} | Measure-Object).Count

   if($vdspg = Get-VDSwitch | Sort-Object -Property Name | Get-VDPortgroup)

     {

     $ImpactedDVS = @()

     ForEach($PG in $vdspg | Where-Object{-not $_.IsUplink -and $_.PortBinding -ne 'Ephemeral' -and -not ($_.PortBinding -eq 'Static' -and $_.ExtensionData.Config.AutoExpand)})

       {

       $NumVMkPorts = (Get-VMHostNetworkAdapter -DistributedSwitch $PG.VDSwitch.Name | Where-Object {$_.DeviceName -like 'vmk*' -and $_.PortGroupName -eq $PG.Name} | Measure-Object).Count   ### Inserted here ###

       $NumPorts = $PG.NumPorts

       $NumVMs = ($PG.ExtensionData.VM).Count

       $OpenPorts = $NumPorts - $NumVMs - $NumVMkPorts

       $myObj = "" | Select vDSwitch,Name,OpenPorts,NumPorts,NumVMs,NumVMkPorts

       $myObj.vDSwitch    = $PG.VDSwitch.Name

       $myObj.Name        = $PG.Name

       $myObj.OpenPorts   = $OpenPorts

       $myObj.NumPorts    = $NumPorts         

       $myObj.NumVMs      = $NumVMs          

       $myObj.NumVMkPorts = $NumVMkPorts      

       $ImpactedDVS += $myObj

       }

     $ImpactedDVS

     }

Reply
0 Kudos