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?
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}}
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}}
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
}
