Updating the VMware vCenter License Key using PowerCLI



PowerCLI PowerShell Licensing

Published on 14 June 2019 by Christopher Lewis. Words: 232. Reading Time: 2 mins.

Out of the blue this week, I had a query from a colleague about being able to update the vCenter License key programmatically via PowerShell/PowerCLI. This is something I have done before so luckily I had a script.

The main license update component is here:


$LM = get-view($vCenter.ExtensionData.content.LicenseManager)
$LM.AddLicense($vCenter6License,$null)
$LAM = get-view($LicenseManager.licenseAssignmentManager)
$LAM.UpdateAssignedLicense($vCenter.InstanceUuid,$vCenter6License,$Null)

For a fully working script we can top and tail the above code with the usual variable and connectivity statements for vCenter:


$vCenterServer=[vCenter FQDN]
$User=[vCenter Username]
$Password=[vCenter Password]
$License = [vCenter License Key]

$EncryptedPassword = ConvertTo-SecureString -String "$Password" -AsPlainText -Force`

$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $EncryptedPassword`
  
Disconnect-VIServer -confirm:$false -ErrorAction SilentlyContinue
Write-Host "Connecting to $vCenterServer"
$vCenter = Connect-VIServer -Server $vCenterServer -Credential $Credential
$LM = get-view($vCenter.ExtensionData.content.LicenseManager)
$LM.AddLicense($License,$null)
$LAM = get-view($LicenseManager.licenseAssignmentManager)
$LAM.UpdateAssignedLicense($vCenter.InstanceUuid,$License,$Null)

And hey presto!

The script can also be found in my PowerShell github repo.


Once that change has been made, the script should work.

If it doesn’t please let me know via social media!

Published on 14 June 2019 by Christopher Lewis. Words: 232. Reading Time: 2 mins.