COS
Expert
Expert

Get list of VDPortGroup for each datacenter and cluster

Jump to solution

I need to get a list of VDPortGroups from each datacenter and eac cluster in my vCenter server called "Junkyard".

I need the output to be formatted in a table like below....

      

vCenterServerDatacenterNameClusterNameVDPortGroup
JunkyardScrappyScrappyDoodv-prod
JunkyardCrappyCrappyDoodv-dev
JunkyardSnappySnappyDoodv-test
JunkyardNappyNappyDoodv-kaboom

That's just a sample, there actually a hundred more...…..lol

Now, I apparently have an old version of PowerCLI, see below.....

Every time I try and upgrade, PowerCLI prompts for authentication and I can't have that. Will try and fix later.

Get-Module -Name VMware* -ListAvailable

    Directory: C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Modules

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     6.0.0.0    VMware.DeployAutomation
Binary     6.0.0.0    VMware.ImageBuilder
Binary     6.5.0.4... VMware.VimAutomation.Cis.Core
Binary     6.5.0.4... VMware.VimAutomation.Cloud
Manifest   6.5.0.4... VMware.VimAutomation.Common
Binary     6.5.0.2... VMware.VimAutomation.Core           HookGetViewAutoCompleter
Binary     6.0.0.0    VMware.VimAutomation.HA
Binary     7.0.2.4... VMware.VimAutomation.HorizonView
Binary     6.5.0.4... VMware.VimAutomation.License
Binary     6.5.0.4... VMware.VimAutomation.PCloud
Manifest   6.5.0.4... VMware.VimAutomation.Sdk            Get-PSVersion
Binary     6.5.0.4... VMware.VimAutomation.Storage
Binary     6.5.0.4... VMware.VimAutomation.Vds
Binary     6.5.0.4... VMware.VimAutomation.vROps
Binary     6.0.0.0    VMware.VumAutomation

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

You obviously still have a MSI-based installed of PowerCLI.
When that is installed for AllUsers, you most probably need administrator authority to uninstall the package.

For the script try something like this

$vcName = 'Junkyard'

Get-Datacenter -Server $vcName -PipelineVariable dc |

ForEach-Object -Process {

    Get-Cluster -Location $dc -Server $vcName -PipelineVariable cluster |

    ForEach-Object -Process {

        Get-VMHost -Location $cluster -Server $vcName |

        Get-VDswitch -Server $vcName |

        Get-VDPortgroup -Server $vcName |

        Select @{N='vCenter';E={$vcName}},

            @{N='Datacenter';E={$dc.Name}},

            @{N='Cluster';E={$cluster.Name}},

            @{N='VDPortgroup';E={$_.Name}}

    }

}


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

View solution in original post

8 Replies
LucD
Leadership
Leadership

You obviously still have a MSI-based installed of PowerCLI.
When that is installed for AllUsers, you most probably need administrator authority to uninstall the package.

For the script try something like this

$vcName = 'Junkyard'

Get-Datacenter -Server $vcName -PipelineVariable dc |

ForEach-Object -Process {

    Get-Cluster -Location $dc -Server $vcName -PipelineVariable cluster |

    ForEach-Object -Process {

        Get-VMHost -Location $cluster -Server $vcName |

        Get-VDswitch -Server $vcName |

        Get-VDPortgroup -Server $vcName |

        Select @{N='vCenter';E={$vcName}},

            @{N='Datacenter';E={$dc.Name}},

            @{N='Cluster';E={$cluster.Name}},

            @{N='VDPortgroup';E={$_.Name}}

    }

}


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

COS
Expert
Expert

I have admin rights. I ran everythin on a "run as..." also but same results.

Should I do a full uninstall then reinstall from the link you sent previously?

Thanks

0 Kudos
LucD
Leadership
Leadership

Since it looks to be a MSI installation, I would advise to first try and uninstall via the Control Panel - Programs and Features.

Then manually remove the folder C:\Program Files (x86)\VMware\Infrastructure\PowerCLI and everything in it, should it still be there.

Then, perhaps do a reboot to be on the safe side first, install PowerCLI again with the Install-Module cmdlet.

The steps are documented in more detail in Welcome PowerCLI to the PowerShell Gallery – Install Process Updates


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

0 Kudos
sivagndl
Enthusiast
Enthusiast

HI Lucd,

     Can we get vms count each cluster using below script ?

vcName = 'Junkyard'

Get-Datacenter -Server $vcName -PipelineVariable dc |

ForEach-Object -Process {

    Get-Cluster -Location $dc -Server $vcName -PipelineVariable cluster |

    ForEach-Object -Process {

        Get-VMHost -Location $cluster -Server $vcName |

        Get-VDswitch -Server $vcName |

        Get-VDPortgroup -Server $vcName |

        Select @{N='vCenter';E={$vcName}},

            @{N='Datacenter';E={$dc.Name}},

            @{N='Cluster';E={$cluster.Name}},

            @{N='VDPortgroup';E={$_.Name}}

    }

}

0 Kudos
LucD
Leadership
Leadership

Try adding this calculated property

            @{N='VMperCluster';E={(Get-VM -Location $cluster).Count}},


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

0 Kudos
sivagndl
Enthusiast
Enthusiast

Thanks lucd. Its giving cluster vm count. expecting each portgroup vms count.

0 Kudos
LucD
Leadership
Leadership

You did ask "Can we get vms count each cluster using below script ?"

In any case, try like this

            @{N='VMperVDPG';E={$_.ExtensionData.Vm.Count}},


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

0 Kudos
sivagndl
Enthusiast
Enthusiast

Thanks Lucd..

0 Kudos