leitsu
Contributor
Contributor

Retrieve vcenter license key

Jump to solution

Hi

Is it possible to retreive vcenter license key using PowerCLI?


1 Solution

Accepted Solutions
mattboren
Expert
Expert

Hello-

You can just add in a calculated property to have the current vCenter name included with the corresponding license info, like:

## array of names of vCenters to which to connect
$arrVCList = "myvc0.mydom.com","myvc1.mydom.com"

&{
foreach ($strVC in $arrVCList) {
   
## connect to this vCenter name
    $oThisVC = Connect-VIServer -Server $strVC
   
## get this vC's license mgr
    $viewLicMgr = Get-View $oThisVC.ExtensionData.Content.LicenseManager -Property Licenses
   
## select some things
    $viewLicMgr.Licenses | select @{n="vCenterName"; e={$oThisVC.Name}},*
   
Disconnect-VIserver $oThisVC -Confirm:$false | Out-Null
}} |
Export-Csv D:\Scripts\License\licenses.csv -NoTypeInformation -UseCulture

I changed it up a bit to keep things in the pipeline a bit more (vs. stuffing the license info into a variable).  That get it?

View solution in original post

3 Replies
mattboren
Expert
Expert

Hello, -

You can use the LicenseManager object for the vCenter to which you last connected in your PowerCLI session, and then display the licenses that it knows of, like:

## get the license manager View object
$viewLicMgr = Get-View $global:DefaultVIServer.ExtensionData.Content.LicenseManager

## display the licenses
$viewLicMgr.Licenses

How does that do for you?

0 Kudos
leitsu
Contributor
Contributor

Thanks. How can I make it displaying the vCenter name?

foreach ($vm in $vmlist) {
Connect-VIServer -Server $vm
$viewLicMgr = Get-View $global:DefaultVIServer.ExtensionData.Content.LicenseManager
$report += $viewLicMgr.Licenses
Disconnect-VIserver $vm -Confirm:$false
}

$report | Export-Csv D:\Scripts\License\licenses.csv -NoTypeInformation -UseCulture

I would like the report to display the vCenter name so I know which vCenter the license belong to....

0 Kudos
mattboren
Expert
Expert

Hello-

You can just add in a calculated property to have the current vCenter name included with the corresponding license info, like:

## array of names of vCenters to which to connect
$arrVCList = "myvc0.mydom.com","myvc1.mydom.com"

&{
foreach ($strVC in $arrVCList) {
   
## connect to this vCenter name
    $oThisVC = Connect-VIServer -Server $strVC
   
## get this vC's license mgr
    $viewLicMgr = Get-View $oThisVC.ExtensionData.Content.LicenseManager -Property Licenses
   
## select some things
    $viewLicMgr.Licenses | select @{n="vCenterName"; e={$oThisVC.Name}},*
   
Disconnect-VIserver $oThisVC -Confirm:$false | Out-Null
}} |
Export-Csv D:\Scripts\License\licenses.csv -NoTypeInformation -UseCulture

I changed it up a bit to keep things in the pipeline a bit more (vs. stuffing the license info into a variable).  That get it?

View solution in original post