MattGGS
Contributor
Contributor

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

Jump to solution

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

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

0 Kudos
2 Replies
LucD
Leadership
Leadership

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

0 Kudos
MattGGS
Contributor
Contributor

Luc,

As always thanks SO MUCH!

0 Kudos