VMware Cloud Community
nicholas1982
Hot Shot
Hot Shot
Jump to solution

How to list Distributed PortGroups that haven't got VM's connected to it?

Hi All,

Just wondering if anyone here knows of a way (script) to list distributed portgroups that haven't got VM's connected to it?

Thanks Nic

Nicholas
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

Get-VDPortgroup | where{$_.ExtensionData.Vm.Count -eq 0} | select VDSwitch,Name


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

Get-VDPortgroup | where{$_.ExtensionData.Vm.Count -eq 0} | select VDSwitch,Name


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

0 Kudos
nicholas1982
Hot Shot
Hot Shot
Jump to solution

Luc,

You are amazing, its exactly what I needed, by any chance would it be possible to add the VLAN ID to that unused portgroup list ?

Nicholas
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, try like this

Get-VDPortgroup | where{$_.ExtensionData.Vm.Count -eq 0} |

select VDSwitch,Name,

    @{N='VlanType';E={$_.VlanConfiguration.VlanType}},

    @{N='VlanId';E={

        $pg = $_

        switch($pg.VlanConfiguration.VlanType){

            'Vlan' {$pg.VlanConfiguration.VlanId}

            'PrivateVlan' {"$($pg.VlanConfiguration.PrimaryVlanId )-$($pg.VlanConfiguration.SecondaryVlanId)"}

            'Trunk' {$pg.VlanConfiguration.Ranges}

        }

    }}


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

nicholas1982
Hot Shot
Hot Shot
Jump to solution

Luc,

I just want to say thank you, this helped us so much and saved us hours of work.

Thanks Nic Smiley Happy

Nicholas
0 Kudos