9 Replies Latest reply on May 31, 2017 3:42 AM by RhysCleverly

    Query Licenses for VC , VCOPS, etc...

    Grzesiekk Expert

      Hi there,

        i am stuck witt this licensing report. How it is possible to make some reference from license key to VC or from key to VC ops. I was googling for few hours and did not find anything about this.

      I would like to pull data about licenses for hosts(i did this), and for all other assets like in the view within vsphere client in Licensing/Management/Asset, is it even possible ?

       

      Thanks in advance for any hints

       

      Regards,

      Greg

        • 1. Re: Query Licenses for VC , VCOPS, etc...
          Grzesiekk Expert

          http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.LicenseAssignmentManager.html

          says that i need just to give the entity ID, it works ok with hosts, but when i try to give as parameter the entity id of vcops appliance for exampla, no output is display.

           

          for example:

          EditionKey      : vco.advanced
          Name            : vCenter Operations Manager 5 Advanced
          Total           : xx
          Used            : yy
          CostUnit        : vm
          Properties      : {ProductName, ProductVersion}
          Labels          : {VpxClientLicenseLabel}
          DynamicType     :
          DynamicProperty :

           

          But thre is no reference here so i can tell which vm is the vcops that is using this key

           

          Regards,

          Greg

           

          #update:

          Ok, now i know how to check the current VC license asignment. I was close tho

          $LicenseAssignmentManager.QueryAssignedLicenses(entityID) ->

          but in case of VC it's virtualcenter Instance Uuid and it's possible to get it from here

          $ServiceInstance = Get-View ServiceInstance

          $LicenseManager= Get-view $ServiceInstance.Content.LicenseManager
          $LicenseAssignmentManager= Get-View $LicenseManager.LicenseAssignmentManager

           

          $LicenseAssignmentManager.QueryAssignedLicenses($ServiceInstance.Content.About.InstanceUuid)


          !!! And this is it.

           

          Reference:

          http://www.lucd.info/2009/10/29/assign-a-vcenter-license/

           

           

           

          But still i am wondering how to get the vcops for example license information.

           

          regards,

          Greg

          • 2. Re: Query Licenses for VC , VCOPS, etc...
            Grzesiekk Expert

            http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.LicenseAssignmentManager.html#queryAssignedLicenses

            Says that

            entityId*xsd:stringID of the entity. E.g. HostSystem.

            *Need not be set

             

            I also found a post here that also says this field can be empty. And if given empty we should receive all licenses from our vc, if it would be , esx ,vc, vcops, whatever is registerd.

            http://www.doublecloud.org/2011/05/new-licensing-apis-since-vmware-vsphere-4/

            "

            Luckily, you don’t have to. The parameter to the queryAssignedLicenses() is optional, and you can bypass that (In VI Java API,  you use null in place of entityId; in MOB, you leave it as empty  string). As a result, you will get all the mappings in the returned  LicenseAssignmentManagerLicenseAssignment[] array. The following table  summarizes the properties in the data object.

            "

            I can confirm this when doing this via https://my_vc/mob/?moid=LicenseAssignmentManager&method=queryAssignedLicenses

            And i leave field EntityID empty.

            As a result i receive nice list of ALL licenses, and also names of products that they were assigned to. So it is even possible to get the name of the VM that is for example my vcops that is registered.

             

            I have tried for an hours to invoke via powercli this method queryAssignedLicenses with 'empty entityID', so i can have the same result as via web browser,  but i did not work for me.

             

            Does anybody know how to invoke the queryAssignedLicenses method with entityID empty somehow to get the results ?

             

            Regards,

            Greg

            • 3. Re: Query Licenses for VC , VCOPS, etc...
              LucD Guru
              Community WarriorsUser ModeratorsvExpert

              Try it like this

               

              $LicenseManager= Get-view LicenseManager
              $LicenseAssignmentManager= Get-View $LicenseManager.LicenseAssignmentManager 
              $param
              = @($null) $LicenseAssignmentManager.GetType().GetMethod("QueryAssignedLicenses").Invoke($LicenseAssignmentManager,$param)
              • 4. Re: Query Licenses for VC , VCOPS, etc...
                Grzesiekk Expert

                Luc !!!!! You are the best !!!!!!!!!!!!!

                THANK YOU SO MUCH

                It works !!!!

                 

                 

                Greg

                 

                Btw. Any idea why

                $LicenseAssignmentManager.QueryAssignedLicenses($param)

                this will not work ?  Becase i was alredy trying with giving the param @($null) and it was not working

                 

                Why do we have to get the method like this?

                • 5. Re: Query Licenses for VC , VCOPS, etc...
                  LucD Guru
                  Community WarriorsvExpertUser Moderators

                  It seems RvdNieuwendijk asked the same question in a private forum.

                   

                  From there I quote the reply from ykalchev who explains it much better than I could have done.

                   

                  PowerCLI  views are generated based on vSphere SDK object but we  don't generate overload methods that skip optional parameters. This will  add more complexity for the methods and in some cases even it's not  possible because of the C# language specifics.

                  The correct way to call method with optional parameters is to pass $null to the these parameters.

                  The ... call does not return anything due to a bug in powershell that  sends empty string instead of $null to the C# methods when parameter is  declared of type String. This is important to know because affects not  only PowerCLI view methods. So instead of querying licenses of all  entities, the call queries licenses to entity id "" and return nothing.

                  • 6. Re: Query Licenses for VC , VCOPS, etc...
                    Grzesiekk Expert

                    Thanks for the explanation. Makes more sense now.

                    Again, thank you for help !

                     

                    Greg

                    • 7. Re: Query Licenses for VC , VCOPS, etc...
                      RvdNieuwendijk Virtuoso
                      User ModeratorsvExpert

                      It is not strange that Greg and I asked the same question, because we have been working together to solve this problem, at the #PowerCLI IRC channel at freenode.net.

                      • 9. Re: Query Licenses for VC , VCOPS, etc...
                        RhysCleverly Lurker

                        Hi Guys,

                         

                        The script looks really impressive good work. I seem to have a problem getting the html file though. I am using these commands from your website...

                         

                         

                        Function Get-LicenseReport

                         

                        {

                          <#

                         

                           .Synopsis

                         

                            Get licensing report from currently connected Virtual Center

                         

                           .Description

                         

                            This function returns licensing information from the currently connected

                            Virtual Center server. It can output to screen or to html file using the

                            ConvertTo-HTML option.

                            PreContent of html report can be modified in source code.

                            Variable $PreContent describes what is written before generating

                            the table.

                         

                           .Example

                         

                            Get-LicenseReport

                         

                            Will create licenses usage report from currently connected VirtualCenter

                            server and output to screen

                         

                           .Example

                         

                            Get-LicenseReport -htmlfile "C:\licensereport.html"

                         

                            Will create licenses usage report from currently connected VirtualCenter

                            server and output to file "C:\licensereport.html"

                           

                            Get-LicenseReport -htmlfile "C:\licensereport.html" -Name "Grzegorz

                            Kulikowski" -Email "myemail@web.com" -CustomerNumber "123123"

                         

                            Will create licenses usage report from currently connected VirtualCenter

                            server and output to file "C:\licensereport.html" and fill out predefined

                            field within report such as name, email, vmware customer number

                         

                           .Parameter CustomerNumber

                         

                            If you need to specifi additional field like Customer Number

                           

                            .Parameter Name

                         

                            If you need to specify name of the person who creates the report

                           

                            .Parameter Email

                         

                            If you need to specify e-mail of the person who creates the report

                           

                           .Parameter htmlfile

                         

                            Specifies the file name to which html version report will be written

                         

                           .Notes

                         

                            NAME:  Get-LicenseReport

                         

                            AUTHOR: Grzegorz Kulikowski

                         

                            LASTEDIT: 08/13/2012

                           

                            SPECIAL THANKS: Luc Dekens, Robert van den Nieuwendijk, Yasen Kalchev

                            CSS TABLE: http://www.textfixer.com/resources/css-tables.ph

                           

                            NOT WORKING ? #powercli @ freenode.irc.net /

                         

                           .Link

                         

                            https://psvmware.wordpress.com

                         

                        #>

                        param (

                        [string]$htmlfile,

                        [string]$CustomerNumber,

                        [string]$Name,

                        [string]$Email

                        )

                        $Head=@"

                        <Title>License Report for $($global:DefaultVIServer.name)</Title>

                        <Style type="text/css">

                          P.myinfo {text-align: Left}

                          body {

                           margin-left: 20%;

                           margin-right: 20%;

                           padding-top: 30px;

                           padding-bottom: 40px;

                           color: #2E2E2E;

                           background-color: #E6E6E6 }

                          

                          table.gridtable {

                            font-family: verdana,arial,sans-serif;

                            font-size:11px;

                            color:#333333;

                            border-width: 1px;

                            border-color: #666666;

                            border-collapse: collapse;

                        }

                          table.gridtable th {

                            border-width: 1px;

                            padding: 8px;

                            border-style: solid;

                            border-color: #666666;

                            background-color: #dedede;

                        }

                          table.gridtable td {

                            border-width: 1px;

                            padding: 8px;

                            border-style: solid;

                            border-color: #666666;

                            background-color: #ffffff;

                        }

                        </Style>

                        "@

                        $PreContent=@"

                        <center>

                        <p><h1>License Report</h1></p>

                        <p class="myinfo">VMware License Review – for VC:<b> $($global:DefaultVIServer.name) </b></br>

                        Customer Number:<b> $CustomerNumber </b></br>

                        Name of Person completing this form: <b>$Name</b></br>

                        Email of Person completing this form: <b>$Email</b></br>

                        Date: <b> $(get-date) </b></br></br</p>

                        "@

                         

                        if(-not ($global:DefaultVIServer) ) {

                            Write-Host -ForegroundColor Red -BackgroundColor Black "You are not connected to any VirtualCenter server. Please connect manually."

                            Write-Host -ForegroundColor Yellow -BackgroundColor Black "hint: Connect-VIServer -server myVC.domain.biz -Credential (Get-Credential)"

                            break

                        }

                        $param = @($null)

                        $ServiceInstance = Get-View ServiceInstance

                        $LicenseManager= Get-view $ServiceInstance.Content.LicenseManager

                        $LicenseAssignmentManager= Get-View $LicenseManager.LicenseAssignmentManager

                        $LicensesArrayList=New-Object System.Collections.ArrayList

                        $LicenseAssignmentManager.GetType().GetMethod("QueryAssignedLicenses").Invoke($LicenseAssignmentManager,$param) |Foreach-Object{

                        $License=New-Object -TypeName PsObject -Property @{ProductName=$null;Version=$null;Edition=$null;DisplayName=$null;PhysProcessors=$null;CoresPerCpu=$null}

                        $License.ProductName= ($_.Properties.GetEnumerator()|?{$_.Key -eq 'ProductName'}).Value

                        $License.Version= ($_.Properties.GetEnumerator()|?{$_.Key -eq 'ProductVersion'}).Value

                        $License.Edition= $_.AssignedLicense.Name

                        $License.DisplayName=$_.EntityDisplayName

                            if($_.AssignedLicense.EditionKey -like "vco*"){

                                    $License.DisplayName+=" Used: $($_.AssignedLicense.Used) from: $($_.AssignedLicense.Total)"

                                }

                            if($_.EntityId -like "host-*"){

                                $HostView=Get-View -Id  "HostSystem-$($_.EntityID)"

                                $License.PhysProcessors=$HostView.Hardware.CpuInfo.NumCpuPackages

                                $License.CoresPerCpu=$hostview.Hardware.CpuInfo.NumCpuCores/$HostView.Hardware.CpuInfo.NumCpuPackages

                            }

                                else {

                                    $License.PhysProcessors="N/A"

                                    $License.CoresPerCpu="N/A"

                                }

                        $LicensesArrayList.Add($License)|Out-Null

                        }

                        if($htmlfile){

                            ($LicensesArrayList | Select-Object ProductName,Version,Edition,DisplayName,CoresPerCpu,PhysProcessors | ConvertTo-Html -PreContent $PreContent -Head $Head ) -Replace '<table>','<table class="gridtable">' |Out-File $htmlfile

                            }

                            else{

                                return $LicensesArrayList

                            }

                        }

                         

                        No errors appear and it just stays like that on the screen. Forgive me if i am doing anything wrong but im new to powercli to testing things :-) Any help would be much appreciated

                         

                        Grzesiekk