Automation

 View Only
Expand all | Collapse all

Script to export License usage report from Vcenter

Kanji5575

Kanji5575Mar 18, 2018 08:45 AM

LucD

LucDJun 12, 2022 05:00 PM

  • 1.  Script to export License usage report from Vcenter

    Posted Mar 13, 2018 11:24 AM

    Can someone help me with script to Export License usage report from Vcenter. This is done manually by logging into webclient> Licensing> reports> products > Export License Usage Report > .



  • 2.  RE: Script to export License usage report from Vcenter

    Posted Mar 13, 2018 11:32 AM


  • 3.  RE: Script to export License usage report from Vcenter

    Posted Mar 13, 2018 12:09 PM

    Try like the script I gave in Re: Get Licensing Asset

    It resembles better what that export is doing.



  • 4.  RE: Script to export License usage report from Vcenter

    Posted Mar 14, 2018 07:38 AM

    Lucd,

    Thanks a ton for your quick reply.

    I am sorry for being so silly . I'm in the process of learning it.

    Export usage report from the Web-client has all the below columns.

    1. I am unable to find the properties to pull all the below columns as per the usage report .

    License KeyProduct EditionCost UnitLicense Key ExpirationAsset IDAsset Build VersionUsageCapacityvCenter ServersTime-stamp

    2 . Also as given in the Gui, is there a way on the script we can add timestamp column so we can choose custom dates everytime its run.



  • 5.  RE: Script to export License usage report from Vcenter
    Best Answer

    Posted Mar 14, 2018 08:34 AM

    The LicenseManager takes a daily snapshot of the license assignments.

    That snapshot info is used to create the License Report over a time period.

    Afaik, public access to these snapshots via an API is not available, so I'm afraid that a report over time is currently not possible.

    You can report what the situation is when you run the script.

    What properties, besides the timestamp, are you missing?

    I update a few property names.

    $LicenseManager= Get-view LicenseManager

    $LicenseAssignmentManager= Get-View $LicenseManager.LicenseAssignmentManager

    $LicenseAssignmentManager.GetType().GetMethod("QueryAssignedLicenses").Invoke($LicenseAssignmentManager,@($null)) |

    Select EntityDisplayName,

        @{N='License Key';E={$_.AssignedLicense.LicenseKey}},

        @{N='Product Edition';E={$_.Properties | where{$_.Key -eq 'ProductName'} | select -ExpandProperty Value}},

        @{N='Cost Unit';E={$_.AssignedLicense.CostUnit}},

        @{N='Asset ID';E={$_.EntityID}},

        @{N='Asset Build Version';E={$_.Properties | where{$_.Key -eq 'ProductName'} | select -ExpandProperty Value}},

        @{N='Usage';E={$_.Properties | where{$_.Key -eq 'FileVersion'} | select -ExpandProperty Value}},

        @{N='Used License';E={$_.Properties | where{$_.Key -eq 'EntityCost'} | select -ExpandProperty Value}},

        @{N='Total';E={$_.AssignedLicense.Total}}



  • 6.  RE: Script to export License usage report from Vcenter

    Posted Mar 18, 2018 08:45 AM

    Thanks a ton Lucd. it really helps



  • 7.  RE: Script to export License usage report from Vcenter

    Posted Mar 19, 2018 05:47 AM

    Thanks for sharing the great script Luc,

    What does the Total Column mean?

    if it shows 0 does it means the license is fully utilized while the remaining values are the unused license. cmiiw



  • 8.  RE: Script to export License usage report from Vcenter

    Posted Mar 19, 2018 06:01 AM

    The description of the Total property in LicenseManagerLicenseInfo states "Total number of units contain in the license".

    In other words, how many 'costUnits' are present in this license.

    For example, an ESXi Enterprise License where Total says 10, means that 10 CPU blocks (costUnit) can be licensed.



  • 9.  RE: Script to export License usage report from Vcenter

    Posted Mar 19, 2018 12:26 PM

    Cool, thanks Luc for your clarification :-)



  • 10.  RE: Script to export License usage report from Vcenter

    Posted Feb 24, 2021 03:59 PM

    how can i filter this script to show only licensing info for certain Products, for example 'VMware vCenter Site Recovery Manager'



  • 11.  RE: Script to export License usage report from Vcenter

    Posted Feb 24, 2021 05:23 PM

    You could use a Where-clause similar to this

    $LicenseManager= Get-view LicenseManager
    $LicenseAssignmentManager= Get-View $LicenseManager.LicenseAssignmentManager
    $LicenseAssignmentManager.GetType().GetMethod("QueryAssignedLicenses").Invoke($LicenseAssignmentManager,@($null)) |
    where{$_.Properties | where{$_.Key -eq 'ProductName' -and $_.Value -eq 'VMware vCenter Site Recovery Manager'}} |
    Select EntityDisplayName,
        @{N='License Key';E={$_.AssignedLicense.LicenseKey}},
        @{N='Product Edition';E={$_.Properties | where{$_.Key -eq 'ProductName'} | select -ExpandProperty Value}},
        @{N='Cost Unit';E={$_.AssignedLicense.CostUnit}},
        @{N='Asset ID';E={$_.EntityID}},
        @{N='Asset Build Version';E={$_.Properties | where{$_.Key -eq 'ProductName'} | select -ExpandProperty Value}},
        @{N='Usage';E={$_.Properties | where{$_.Key -eq 'FileVersion'} | select -ExpandProperty Value}},
        @{N='Used License';E={$_.Properties | where{$_.Key -eq 'EntityCost'} | select -ExpandProperty Value}},
        @{N='Total';E={$_.AssignedLicense.Total}}
    


  • 12.  RE: Script to export License usage report from Vcenter

    Broadcom Employee
    Posted Dec 22, 2021 06:47 AM

    Hi LucD, Your abilities are always of great help to me.
    We has 1600 over ESXi hosts. But we get an error. can you help me what could be the reason?

    $licenseManager = Get-View LicenseManager
    $LicenseAssignmentManager = Get-View $licenseManager.LicenseAssignmentManager
    
    $licenseAssignment = $LicenseAssignmentManager.GetType().GetMethod("QueryAssignedLicenses").Invoke($LicenseAssignmentManager, @($null)) | `
    	Select EntityDisplayName, `
    	@{N='Product';E={$_.Properties | where{$_.Key -eq 'ProductName'} | select -ExpandProperty Value}},`
    	@{N='Product Version';E={$_.Properties | where{$_.Key -eq 'FileVersion'} | select -ExpandProperty Value}},`
    	@{N='License';E={$_.AssignedLicense.LicenseKey}},`
    	@{N='License Name';E={$_.AssignedLicense.Name}},`
    	@{N='Used License';E={$_.Properties | where{$_.Key -eq 'EntityCost'} | select -ExpandProperty Value}},`
    	@{N='Total';E={$_.AssignedLicense.Total}} |`
    	Where 'Used License' -gt 0
    
    Exception calling "Invoke" with "2" argument(s). "A general system error occurred: Operation timed out" 
    + $licenseAssignment = $LicenseAssignmentManager.GetType().GetMethod("Q ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : VimException

     



  • 13.  RE: Script to export License usage report from Vcenter

    Posted Dec 22, 2021 08:12 AM

    That looks as if one or more of your ESXi nodes can't be reached.
    Can you try to pinpoint which ones?
    Does it do this for all the ESXi nodes?



  • 14.  RE: Script to export License usage report from Vcenter

    Broadcom Employee
    Posted Dec 22, 2021 08:32 AM

    Hi LucD!

    Correct. We need license count for all ESXi nodes.

    AFAIK It can communicate with any ESXi node. and no communication with ESXi is required to verify license information.



  • 15.  RE: Script to export License usage report from Vcenter

    Posted Dec 22, 2021 08:44 AM

    There is for one or another reason a timeout reported.

    To debug I would start by looking in the vpxd log.




  • 16.  RE: Script to export License usage report from Vcenter

    Broadcom Employee
    Posted Jan 03, 2022 09:10 AM

    LucD! Happy New Year!

    I show you the log that occurred at that time.
    Please understand, Due to the sensitive information of the customer, Log only part of it is displayed.
    It happened after 6 minutes(360000 ms).
    In my opinion is that Timeout occurs when displaying data through Get-View.

    Please let me know if you need the full log. I will let's find another way.

    2021-12-27T13:34:14.689+09:00 info vpxd[07083] [Originator@6876 sub=vpxLro opID=6efccb78] [VpxLRO] -- BEGIN lro-388281453 -- LicenseAssignmentManager -- vim.LicenseAssignmentManager.queryAssignedLicenses -- 5215962c-b302-9b2e-469b-f39453bd06b6(5253be1b-a67e-3249-8f38-e6266ae9f24f)

    2021-12-27T13:40:14.690+09:00 warning vpxd[07083] [Originator@6876 sub=VpxProfiler opID=6efccb78] LicenseServiceProxy::QueryAssignedLicenses [LicenseServiceProxy::QueryAssignedLicenses] took 360000 ms
    2021-12-27T13:40:14.690+09:00 info vpxd[07083] [Originator@6876 sub=vpxLro opID=6efccb78] [VpxLRO] -- FINISH lro-388281453
    2021-12-27T13:40:14.690+09:00 info vpxd[07083] [Originator@6876 sub=Default opID=6efccb78] [VpxLRO] -- ERROR lro-388281453 -- LicenseAssignmentManager -- vim.LicenseAssignmentManager.queryAssignedLicenses: vmodl.fault.SystemError:
    --> Result:
    --> (vmodl.fault.SystemError) {
    --> faultCause = (vmodl.MethodFault) null,
    --> faultMessage = <unset>,
    --> reason = "Operation timed out"
    --> msg = ""
    --> }
    --> Args:
    -->
    --> Arg entityId:
    -->



  • 17.  RE: Script to export License usage report from Vcenter

    Posted Jan 03, 2022 09:25 AM

    I don't know what is causing the timeout, but I'm pretty sure it is not due to Get-View.
    The Get-View cmdlet does nothing more than launch the API call, and the vpxd log confirms that there is a timeout.

    Before diving in deeper, perhaps you might try a simple restart of the license service (vmware-cis-service)



  • 18.  RE: Script to export License usage report from Vcenter

    Broadcom Employee
    Posted Jan 06, 2022 05:14 AM

    Hi LucD,

    Following your advice, restart the license service and test. But still the problems are the same.



  • 19.  RE: Script to export License usage report from Vcenter

    Posted Jan 06, 2022 06:54 AM

    Then you better open an SR



  • 20.  RE: Script to export License usage report from Vcenter

    Broadcom Employee
    Posted Jan 06, 2022 06:57 AM

    Thanks LucD,

    We are currently analyzing the details through SR.

    I'll let you know as soon as the cause is identified.



  • 21.  RE: Script to export License usage report from Vcenter

    Posted Jun 12, 2022 04:36 PM

    Hi , How can I export these licenses details please . I tried to put | export-csv $outputpath but its not collecting the details.

    please can you help me .



  • 22.  RE: Script to export License usage report from Vcenter

    Posted Jun 12, 2022 05:00 PM

    Works for me



  • 23.  RE: Script to export License usage report from Vcenter

    Posted Jun 22, 2022 04:29 PM

    HI LucD,

     I receive the following error on line 3   ($LicenseAssignmentManager.GetType().GetMethod("QueryAssignedLicenses").Invoke($LicenseAssignmentManager,@($null)) |), when I try executing the script  .  It says I cant use "null"

     

     

    Naga2_0-1655915253754.png

     



  • 24.  RE: Script to export License usage report from Vcenter

    Posted Jun 22, 2022 04:41 PM

    Did the first 2 lines produce any errors?
    Is there anything in $LicenseAssignmentManager?



  • 25.  RE: Script to export License usage report from Vcenter

    Posted Jun 22, 2022 05:07 PM

    Nope,, It doesn't , however, in the 3rd line also ,  it gave me an error for  $LicenseAssignmentManager  and I cant use "null" expressions or variables



  • 26.  RE: Script to export License usage report from Vcenter

    Posted Jun 22, 2022 05:24 PM

    Can you be more specific, perhaps add a screenshot?
    Did you check the content of $LicenseAssignmentManager?



  • 27.  RE: Script to export License usage report from Vcenter

    Posted Jun 22, 2022 05:36 PM

    Please find the screenshot for you reference.  Am new to the powercli scripting, I dont know if am doing something wrong

     

    Naga2_1-1655919335128.png

     

     



  • 28.  RE: Script to export License usage report from Vcenter

    Posted Jun 22, 2022 05:43 PM

    Can you just type $LicenseAssignmentManager at the command prompt, and check what it returns?



  • 29.  RE: Script to export License usage report from Vcenter

    Posted Jun 22, 2022 06:16 PM

    Here you go .

     

    Naga2_0-1655921725610.png

     



  • 30.  RE: Script to export License usage report from Vcenter

    Posted Jun 22, 2022 06:32 PM

    Ok, I know what happened.
    You have multiple vCenter connections open.
    You can check with displaying $global:defaultVIServers.

    Close all those connections with

    Disconnect-VIServer -Server * -Force -Confirm:$false


    Then run that code again.
    But perhaps add a Disconnect-VIServer at the end of the script to avoid the same issue on a 2nd or subsequent run of the script