VMware Cloud Community
afhamsani
Enthusiast
Enthusiast
Jump to solution

Get Licensing Asset

Hi experts in powerCLI,
do you have powercli code that able to retrieve licensing asset report in csv format according to screenshot here,

as i was thinking to have this as automated rather than access each vcenters manually.

Your help is much appreciated.

Licensing Asset.JPG

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You didn't mention your vSphere, nor PowerCLI version, I assume you're on the latest versions.

Try something like this

$LicenseManager= Get-view LicenseManager

$LicenseAssignmentManager= Get-View $LicenseManager.LicenseAssignmentManager

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


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

View solution in original post

Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

You didn't mention your vSphere, nor PowerCLI version, I assume you're on the latest versions.

Try something like this

$LicenseManager= Get-view LicenseManager

$LicenseAssignmentManager= Get-View $LicenseManager.LicenseAssignmentManager

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


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

Reply
0 Kudos
YuvarajSekar01
Enthusiast
Enthusiast
Jump to solution

Hi, Thanks for the script. Its working fine to me. Can you please help me in getting in the CSV format.

Thanks in Advance,

Yuvaraj

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, try like this

$LicenseManager= Get-view LicenseManager

$LicenseAssignmentManager= Get-View $LicenseManager.LicenseAssignmentManager

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

Export-Csv report.csv -NoTypeInformation -UseCulture


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

Reply
0 Kudos
afhamsani
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

Apologies delay in coming back to you on this, to let you know I haven't had chance to try this but since this coming over from you it should be flawless Smiley Happy

I will get back to you soon on this.

Cheers!

Reply
0 Kudos
afhamsani
Enthusiast
Enthusiast
Jump to solution

LucD mahaguru,

You are purely genius.

How or where should i refer to start learn on powershell scripting?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

It depends a bit on how you want to learn, from a book, a CBT...?

There are some good entry level books available on PowerShell, see for example ew to PowerCLI. Book recommendations

There are also some good PowerShell CBTs from PluralSight


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

Reply
0 Kudos
hlefranc92
Contributor
Contributor
Jump to solution

Good job, thank you for this useful code !

Reply
0 Kudos
vmCalgary
Enthusiast
Enthusiast
Jump to solution


@LucD wrote:

Sure, try like this

 

$LicenseManager= Get-view LicenseManager

$LicenseAssignmentManager= Get-View $LicenseManager.LicenseAssignmentManager

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

Export-Csv report.csv -NoTypeInformation -UseCulture

 


Hi @LucD ,

What do I need to add to get two more columns: Cluster and vcenter?

EntityDisplayName   Product                         Product Version      License     Name          Used LicenseTotal Cluster vcenter   CPU Sockets

vh529no.sjrb.adVMware ESX Server6.5.3.1removedVMware vSphere 6 Enterprise24CG-NO-MGMTvc009no2
vh576no.sjrb.adVMware ESX Server6.5.3.1removedVMware vSphere 6 Enterprise24CG-NO-MGMTvc009no2
vh571no.sjrb.adVMware ESX Server6.5.3.1removedVMware vSphere 6 Enterprise24CG-NO-MGMTvc009no2
vh532no.sjrb.adVMware ESX Server6.5.3.1removedVMware vSphere 6 Enterprise24CG-NO-MGMTvc009no2
vh531no.sjrb.adVMware ESX Server6.5.3.1removedVMware vSphere 6 Enterprise24CG-NO-MGMTvc009no2
vc009no.sjrb.adVMware VirtualCenter Server6.7.0.0removedVMware vCenter Server 6 Standard11CG-NO-MGMTvc009no2
vh575no.sjrb.adVMware ESX Server6.5.3.1removedVMware vSphere 6 Enterprise24CG-NO-MGMTvc009no2
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$LicenseManager= Get-view LicenseManager
$LicenseAssignmentManager= Get-View $LicenseManager.LicenseAssignmentManager
$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}},
    @{N='Cluster';E={
      $lic = $_
      switch($_.EntityId.Split('-')[0]){
        'host' {
          $script:object = Get-VMHost -Name $lic.EntityDisplayName
          (Get-Cluster -VMHost $script:object).Name
        }
        'domain' {
          $script:object = Get-Cluster -Name $lic.EntityDisplayName
          $lic.EntityDisplayName
        }
        Default {
          $script:object = ''
          'na'
        }
      }
    }},
    @{N='vCenter';E={
      if($_.EntityId.Split('-')[0] -in 'host','domain'){
          ([uri]$script:object.ExtensionData.Client.ServiceUrl).Host
        }
        else {
          $_.EntityDisplayName
        }
    }} |
Export-Csv report.csv -NoTypeInformation -UseCulture


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