VMware Cloud Community
MattGGS
Contributor
Contributor
Jump to solution

POWERCLI: How to find dvswitches not used for management (VM only)

I have a script that checks dvswitch properties.  Currently I exclude management dvSwitches by name.   I am trying to figure out how to exclude management dvSwitches (no VM dvPortgroups) from my object via code.   For example:

  • dvswith1
    • dvportgroup-mgmt - vmk0
    • dvportgroup-vmotion - vmk1
  • dvswitch2
    • dvportgroup-vm
    • dvportgroup-vm2

In this example only want it to return dvswitch2

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Something like this?

$tab = @{}

Get-VDSwitch | ForEach-Object -Process {

    $tab.Add($_.Name,'')

}


Get-VMHostNetworkAdapter -VMKernel |

ForEach-Object -Process {

    Get-VDPortgroup -Name $_.PortGroupName -ErrorAction SilentlyContinue |

    Get-VDSwitch | ForEach-Object -Process {

        $tab.Remove($_.Name)

    }

}

$tab.GetEnumerator()


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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Something like this?

$tab = @{}

Get-VDSwitch | ForEach-Object -Process {

    $tab.Add($_.Name,'')

}


Get-VMHostNetworkAdapter -VMKernel |

ForEach-Object -Process {

    Get-VDPortgroup -Name $_.PortGroupName -ErrorAction SilentlyContinue |

    Get-VDSwitch | ForEach-Object -Process {

        $tab.Remove($_.Name)

    }

}

$tab.GetEnumerator()


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

Reply
0 Kudos
MattGGS
Contributor
Contributor
Jump to solution

Luc,

As always thanks SO MUCH!

Reply
0 Kudos