Updating the VMware vCenter License Key using PowerCLI
PowerCLI PowerShell Licensing
Published on 14 June 2019 by Christopher Lewis. Words: 220. 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)
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 $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.
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:
Once that change has been made, the script should work. If it doesn’t please let me know!
Blog Categories: VMware PowerCLI
- HOWTO: Install PowerCLI 6.5.1 - As easy as 1-2-3! ()
- HOWTO: Create vRealize Automation User Role in vCenter using PowerCLI ()
- HOWTO: Automate the installation of the External Platform Services Controller using PowerCLI & JSON - Part 2 ()
- HOWTO: Automate the installation of the External Platform Services Controller using PowerCLI & JSON - Part 1 ()
- Book Review: VMware vSphere PowerCLI Reference: Automating vSphere Administration - 2nd Edition ()