PowerCLI

 View Only
  • 1.  Script to retrive total ports and available ports

    Posted Mar 06, 2017 01:41 PM

    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?

    Thanks!



  • 2.  RE: Script to retrive total ports and available ports



  • 3.  RE: Script to retrive total ports and available ports

    Posted Mar 06, 2017 01:50 PM

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



  • 4.  RE: Script to retrive total ports and available ports

    Posted Mar 06, 2017 05:32 PM

    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

        }}



  • 5.  RE: Script to retrive total ports and available ports

    Posted Mar 07, 2017 11:44 AM

    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.



  • 6.  RE: Script to retrive total ports and available ports

    Posted Mar 07, 2017 11:47 AM

    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



  • 7.  RE: Script to retrive total ports and available ports

    Posted Mar 07, 2017 11:51 AM

    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



  • 8.  RE: Script to retrive total ports and available ports

    Posted Mar 07, 2017 12:05 PM

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

    Or can you upgrade to the latest version?



  • 9.  RE: Script to retrive total ports and available ports

    Posted Mar 07, 2017 12:24 PM

    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



  • 10.  RE: Script to retrive total ports and available ports

    Posted Mar 07, 2017 12:36 PM

    I see.

    In that case try replacing the Get-VDSwitch cmdlet by

    Get-VirtualSwitch -Distributed



  • 11.  RE: Script to retrive total ports and available ports

    Posted Mar 07, 2017 01:30 PM

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