VMware Cloud Community
alexander19
Contributor
Contributor

Script to retrive total ports and available ports

Hello,

I would like to get from vSphere Distributed Switch total ports and available ports. I have tried few ways to get this informations, but i could not find a way to accomplish this. Is any chance to create this kind of script?

Capture.PNG

Thanks!

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership

Reply
0 Kudos
alexander19
Contributor
Contributor

I looked on that script but for my project I need total number from that Vswitch if you know what i mean.

Reply
0 Kudos
LucD
Leadership
Leadership

Ok, got it (I think).
Try like this

Get-VDSwitch |

Select Name,

    @{N='Total Ports';E={$_.NumPorts}},

    @{N='Available Ports';E={

        $vds = $_

        $hPorts = $vds.ExtensionData.Config.Host.UplinkPortKey.Count

        $vPorts = (Get-View -Id $vds.ExtensionData.Summary.Vm | %{

                    $_.Config.Hardware.Device |

                    where{$_.Backing -and

                      $_.Backing.GetType().Name -match "distributed" -and

                      $_.Backing.Port.SwitchUuid -eq $vds.ExtensionData.Uuid}}).Count

        $vds.NumPorts - $hPorts - $vPorts

    }}


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

Reply
0 Kudos
alexander19
Contributor
Contributor

I need some packeg or something like that because I get this errror:

Get-VDSwitch : The term 'Get-VDSwitch' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a

path was included, verify that the path is correct and try again.

Reply
0 Kudos
LucD
Leadership
Leadership

Which PowerCLI version are you running?

Do a Get-PowerCLIVersion


If you can upgrade to the latest version, which is modules only, you can just execute the following line once before running the script.

Get-Module -Name VMware* -ListAvailable | Import-Module


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

Reply
0 Kudos
alexander19
Contributor
Contributor

PowerCLI Version

----------------

   VMware vSphere PowerCLI 5.8 Release 1 build 2057893

---------------

Snapin Versions

---------------

   VMWare AutoDeploy PowerCLI Component 5.5 build 1983942

   VMWare ImageBuilder PowerCLI Component 5.5 build 1983942

   VMware License PowerCLI Component 5.5 build 1265954

   VMware Storage PowerCLI Component 5.8 build 2057894

   VMware VDS PowerCLI Component 5.8 build 2031581

   VMware vSphere PowerCLI Component 5.8 build 2031581

Reply
0 Kudos
LucD
Leadership
Leadership

Is there a specific reason you're on that older release?

Or can you upgrade to the latest version?


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

Reply
0 Kudos
alexander19
Contributor
Contributor

unfortunately i need to kep this version because is a productive enviroment and i cannot upgrade to last version because currently we have a lot of script running over this version, so it will take a lot of work and time if i will upgrade to last version

Reply
0 Kudos
LucD
Leadership
Leadership

I see.

In that case try replacing the Get-VDSwitch cmdlet by

Get-VirtualSwitch -Distributed


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

Reply
0 Kudos
alexander19
Contributor
Contributor

Just perfect. Work as  was expected. Thank you very much!

Reply
0 Kudos