Automation

 View Only
  • 1.  To fetch overused license allocation

    Posted Apr 20, 2015 02:28 PM

    Hi all,

    Need help to create a script for fetching over allocated license from a vcenter.

    I have written a script, which gives the total number of CPU unallocated/overallocated. but its not meeting the actual requirement.

    ==========================

    $ServiceInstance = Get-View ServiceInstance

    # Fetches Total license Enterprise plus license count

    $LicenseTotal = (Get-View ($ServiceInstance | Select -First 1).Content.LicenseManager | select -ExpandProperty licenses | ? {$_.Name -match "VMware vsphere 5 Enterprise Plus"} | select Total | Measure-Object -Property Total -sum).Sum

    # Fetches Total Physical CPU cores in the vcenter.
    $CPUTotal = (Get-VMHost | Get-View | Select -ExpandProperty Hardware | Select -ExpandProperty CpuInfo | Measure-Object -Property NumCpuPackages -Sum).Sum
    Write-host "License Total is $LicenseTotal"
    Write-host "CPU Total is $CPUTotal"

    $diff = [int]$LicenseTotal - [int]$CPUTotal

    if ($LicenseTotal -gt $CPUtotal)
    {
      "We have $diff  number of free License available"
    }
      elseif ($LicenseTotal.tovalue -eq $CPUtotal.tovalue)
    {
       "All the License are assigned"
            }
       else
            {
         "$diff *-1  number of license required to make it compliant"
             }

    # Fetches Total
    Get-View ($ServiceInstance | Select -First 1).Content.LicenseManager | select -ExpandProperty licenses | ? {$_.Name -match "Evaluation"} | select LicenseKey, EditionKey,Name,Used,Total| ft -autosize

    =======================================

    Need output something as below.

    S.NOLicense Key

    Allocation status

    1xxy-xx-xx-exx2 CPUs  license overallocated
    2xxx-xx-xx-xx2 CPUs license free

    Though not exactly, it will be useful if I could get output similar to above.

    Only overallocated and underallocated License information is required.



  • 2.  RE: To fetch overused license allocation

    Posted Apr 21, 2015 10:21 AM

    Any solution for my query please...



  • 3.  RE: To fetch overused license allocation

    Posted Apr 21, 2015 11:04 AM

    You mean something like this ?

    $si = Get-View ServiceInstance | Select -First 1

    $licMgr = Get-View $si.Content.LicenseManager

    $i = 0

    $licMgr.Licenses | where{$_.Name -eq 'VMware vSphere 5 Enterprise Plus'} | %{

        [pscustomobject]@{

            'S.No' = $i

            'License Key' = $_.LicenseKey

            'Allocation Status' = &{

                if($_.Used -gt $_.Total){

                    "$($_.Used - $_.Total) CPU license overallocated"

                }

                else{

                    "$($_.Total - $_.Used) CPU license free"

                }

            }

        }

    }



  • 4.  RE: To fetch overused license allocation

    Posted May 05, 2015 07:51 PM

    Thanks LucD, Now i wish to check whether

    1) a specific license is being used in different vcenters and if used it needs to be reported.

    2) License is overutilized than its capacity.

    Can you please help on this..

    Thanks in advance.





  • 5.  RE: To fetch overused license allocation

    Posted May 05, 2015 07:58 PM

    How do you know which vCenters to connect to ?

    Are they defined somewhere ?

    Are you running in "multiple" or "single" mode ?

    You can connect to each vCenter in turn, collect the information from the script above and store it in an array, and then check if a specific license is already used.



  • 6.  RE: To fetch overused license allocation

    Posted May 05, 2015 08:24 PM

    1) How do you know which vCenters to connect to ?

              We have 6 vcenters and this script needs to check by connecting to all vcenter servers.

    2) Are they defined somewhere ?

         Should be defined so that before the script starts execution, it will be connected to all the vcenters.

    3) Are you running in "multiple" or "single" mode ?

              They are all single vcenters, not in linked mode.