Automation

 View Only
Expand all | Collapse all

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

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

    Posted Aug 31, 2020 07:59 PM

    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



  • 2.  RE: POWERCLI: How to find dvswitches not used for management (VM only)
    Best Answer

    Posted Aug 31, 2020 08:07 PM

    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()



  • 3.  RE: POWERCLI: How to find dvswitches not used for management (VM only)

    Posted Sep 01, 2020 01:55 PM

    Luc,

    As always thanks SO MUCH!