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.
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
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
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
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
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
I will get back to you soon on this.
Cheers!
LucD mahaguru,
You are purely genius.
How or where should i refer to start learn on powershell scripting?
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
Good job, thank you for this useful code !
@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.ad | VMware ESX Server | 6.5.3.1 | removed | VMware vSphere 6 Enterprise | 2 | 4 | CG-NO-MGMT | vc009no | 2 |
vh576no.sjrb.ad | VMware ESX Server | 6.5.3.1 | removed | VMware vSphere 6 Enterprise | 2 | 4 | CG-NO-MGMT | vc009no | 2 |
vh571no.sjrb.ad | VMware ESX Server | 6.5.3.1 | removed | VMware vSphere 6 Enterprise | 2 | 4 | CG-NO-MGMT | vc009no | 2 |
vh532no.sjrb.ad | VMware ESX Server | 6.5.3.1 | removed | VMware vSphere 6 Enterprise | 2 | 4 | CG-NO-MGMT | vc009no | 2 |
vh531no.sjrb.ad | VMware ESX Server | 6.5.3.1 | removed | VMware vSphere 6 Enterprise | 2 | 4 | CG-NO-MGMT | vc009no | 2 |
vc009no.sjrb.ad | VMware VirtualCenter Server | 6.7.0.0 | removed | VMware vCenter Server 6 Standard | 1 | 1 | CG-NO-MGMT | vc009no | 2 |
vh575no.sjrb.ad | VMware ESX Server | 6.5.3.1 | removed | VMware vSphere 6 Enterprise | 2 | 4 | CG-NO-MGMT | vc009no | 2 |
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