Home > PowerCLI, PowerShell, vSphere > Add license to a vSphere host

Add license to a vSphere host

This is a rather short PowerCLI post.

Licensing is not directly available in PowerCLI cmd-lets, so we’ll have to reach out to the SDK, which is easily accessible from PowerShell.  We’ll have to fetch a LicenseAssignmentManager to set the license, so this mean using quite some Get-View cmdlets.  These could all be combined into a single line of code but makes it hard to read.

$strVMHostName is the name of your ESX(i) server to license

$strLicense is your licensekey.  All zero’s like in the example sets the host to evaluation mode.



$strVMHostName = "HostName.domain.com"

$strLicense = "00000-00000-00000-00000-00000"


$objServiceInstance = Get-View -Id ServiceInstance -Property Content.LicenseManager

$objLicenseManager = Get-View -Id $objServiceInstance.Content.LicenseManager -Property LicenseAssignmentManager

$objLicenseAssignmentManager = Get-View -Id $objLicenseManager.LicenseAssignmentManager

$objVMHost = Get-View -ViewType "HostSystem" -Filter @{Name=$strVMHostName} -Property Config.Host

$objLicenseAssignmentManager.UpdateAssignedLicense($objVMHost.Config.Host.Value, $strLicense, $null)


Categories: PowerCLI, PowerShell, vSphere
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: