VMware Cloud Community
Kanji5575
Contributor
Contributor
Jump to solution

Script to export License usage report from Vcenter

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 > .

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

29 Replies
kwhornlcs
Enthusiast
Enthusiast
Jump to solution

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

It resembles better what that export is doing.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Kanji5575
Contributor
Contributor
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Kanji5575
Contributor
Contributor
Jump to solution

Thanks a ton Lucd. it really helps

Reply
0 Kudos
AlbertWT
Virtuoso
Virtuoso
Jump to solution

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

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

AlbertWT
Virtuoso
Virtuoso
Jump to solution

Cool, thanks Luc for your clarification 🙂

/* Please feel free to provide any comments or input you may have. */
Reply
0 Kudos
BayerCGOps
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Minc49
VMware Employee
VMware Employee
Jump to solution

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

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Minc49
VMware Employee
VMware Employee
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

There is for one or another reason a timeout reported.

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



Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Minc49
VMware Employee
VMware Employee
Jump to solution

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:
-->

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Minc49
VMware Employee
VMware Employee
Jump to solution

Hi LucD,

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Then you better open an SR


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Minc49
VMware Employee
VMware Employee
Jump to solution

Thanks LucD,

We are currently analyzing the details through SR.

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

Reply
0 Kudos