PowerCLI

 View Only
  • 1.  Setting the number of available ports to 0 on all port groups

    Posted Jul 10, 2018 07:05 PM

    I am currently working with a customer that does government work, and has a requirement that all portgroups have 0 ports available. When a new server is spun up, an additional port is added; when it is decommissioned the port is (theoretically) removed. However this has not been the case, and running a small script against all portgroups shows a number that have several or more open ports. I am looking for a way to drop that to 0 without having to go through each manually, but am not finding a way.

    To see what is out there, I am just pulling info from get-virtualportgroup. $_.ExtensionData.PortKeys.Count gives me the total number of ports, $_.ExtensionData.vm.count gives me the number of ports in use, and then I am simply subtracting one from the other to get a "portsleft" variable. Is there an easy way to take that portsleft var and set it to 0?



  • 2.  RE: Setting the number of available ports to 0 on all port groups

    Posted Jul 10, 2018 08:53 PM

    Just to confirm, you are only looking at VDS, not VSS?



  • 3.  RE: Setting the number of available ports to 0 on all port groups

    Posted Jul 11, 2018 12:37 PM

    At this point, that is correct. This customer does not use any VSS for VM traffic. If it is easily done to account for both I would like to see how to do so; who knows what the next customer will be using.



  • 4.  RE: Setting the number of available ports to 0 on all port groups

    Posted Jul 11, 2018 01:57 PM

    I did some experimenting, and I think $vds.ExtensionData.Summary.VM.Count is not a correct value for the number of ports used.

    Especially if a VM has more than 1 vNIC connected to a portgroup on that VDS.

    I came up with the following (it shows the name of the VDS and the number of used ports (by VMs) over the total number of ports).

    foreach($vds in Get-View -ViewType VmwareDistributedVirtualSwitch){

        $pgKeys = $vds.Portgroup.Value

        $nics = Get-View -Id $vds.Summary.vm | %{

          $_.Config.Hardware.Device |

          where{$_ -is [VMware.Vim.VirtualEthernetCard] -and $pgKeys -Contains $_.Backing.Port.PortgroupKey}

        }

       

        "$($vds.Name): $($nics.Count)/$($vds.Config.NumPorts)"

    }

    Can you check if that gives the correct values in your environment?

    Also note that this does not yet take into account the number of ports used by the Uplinks.



  • 5.  RE: Setting the number of available ports to 0 on all port groups

    Posted Jul 11, 2018 03:57 PM

    It appears that snippet shows the proper number for Total ports on all the VDS', but not the $nics.Count seems to be off

    Example:

         dvSwitch-LOC1-Production-Blades: 0/33 - Actual 20/33 in use, 13 available

         dvSwitch-LOC1-Test-Blades: 145/1062 - Actual 811/1062 in use, 251 available



  • 6.  RE: Setting the number of available ports to 0 on all port groups

    Posted Jul 11, 2018 04:04 PM

    Interesting, are those 20 ports in use on the 1st VDS all used by VMs?
    And are the corresponding vNICs on those VMs in a connected state?



  • 7.  RE: Setting the number of available ports to 0 on all port groups

    Posted Jul 11, 2018 04:13 PM

    So, actually only 12 are on VMs. Each of the two hosts has 1 for Management, 1 for vMotion, and 2 uplinks (8 total). Of the 12 VMs, all but one of the VMs are showing connected; the last is a proxy that is powered down.



  • 8.  RE: Setting the number of available ports to 0 on all port groups

    Posted Jul 11, 2018 05:06 PM

    Of course, I forgot the VMKernel connections.

    Back to the lab :smileygrin: