Updating the VMware vCenter License Key using PowerCLI

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:

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

Note: This is not an original script, I found the original script online somewhere. So I definitely do not take the credit!

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
$LicenseManager = get-view($vCenter.ExtensionData.content.LicenseManager)
$LicenseManager.AddLicense($License,$null)
$LicenseAssignmentManager = get-view($LicenseManager.licenseAssignmentManager)
$LicenseAssignmentManager.UpdateAssignedLicense($vCenter.InstanceUuid,$License,$Null)

And hey presto!

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

Note: If you are running PowerShell Core and trying to use the Connect-VIServer command then you may get the following error:

If this is the case, you may need to run the following additional PowerCLI command enable this functionality to work:

Set-PowerCLIConfiguration -InvalidCertificateAction:Ignore

Once that change has been made, the script should work. If it doesn’t please let me know!

Comments are closed.

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑

%d bloggers like this: