VMware Cloud Community
Grzesiekk
Expert
Expert
Jump to solution

Query Licenses for VC , VCOPS, etc...

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

--- @blog https://grzegorzkulikowski.info
Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try it like this

$LicenseManager= Get-view LicenseManager
$LicenseAssignmentManager= Get-View $LicenseManager.LicenseAssignmentManager 
$param
= @($null) $LicenseAssignmentManager.GetType().GetMethod("QueryAssignedLicenses").Invoke($LicenseAssignmentManager,$param)


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

View solution in original post

Reply
0 Kudos
9 Replies
Grzesiekk
Expert
Expert
Jump to solution

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

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 Smiley Wink

$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

--- @blog https://grzegorzkulikowski.info
Reply
0 Kudos
Grzesiekk
Expert
Expert
Jump to solution

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

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

--- @blog https://grzegorzkulikowski.info
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try it like this

$LicenseManager= Get-view LicenseManager
$LicenseAssignmentManager= Get-View $LicenseManager.LicenseAssignmentManager 
$param
= @($null) $LicenseAssignmentManager.GetType().GetMethod("QueryAssignedLicenses").Invoke($LicenseAssignmentManager,$param)


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

Reply
0 Kudos
Grzesiekk
Expert
Expert
Jump to solution

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?

--- @blog https://grzegorzkulikowski.info
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


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

Reply
0 Kudos
Grzesiekk
Expert
Expert
Jump to solution

Thanks for the explanation. Makes more sense now.

Again, thank you for help !

Greg

--- @blog https://grzegorzkulikowski.info
Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

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

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
Grzesiekk
Expert
Expert
Jump to solution

I wanted to share results Smiley Wink

http://psvmware.wordpress.com/2012/08/13/get-licensereport-to-obtain-informations-regarding-licenses...

Again thanks for the help !

Greg

--- @blog https://grzegorzkulikowski.info
Reply
0 Kudos
RhysCleverly
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos