Home > PowerCLI, PowerShell, vSphere > Assign a vCenter license

Assign a vCenter license

October 29th, 2009 Leave a comment Go to comments

An interesting question arrived in my mailbox recently. The user was trying to find out how he could assign a vCenter license. The vSphere API Reference clearly pointed to the UpdateAssignedLicense method.

But the value that should be provided in the entity parameter was a bit of a mystery.  An entity ID for a vCenter was new for me.


Fyi, the vCenter Server I used for testing was running in evaluation mode.

After a lot of trial and error I discovered the VC’s Uuid was the entity ID the method was expecting.

This is the script that does the license assignment

$vcLicName = "vCenter Server 4 Standard"
$servInst = Get-View ServiceInstance
$licMgr = Get-View $servInst.Content.licenseManager
$licAssignMgr = Get-View $licMgr.licenseAssignmentManager
$vcUuid = $servInst.Content.About.InstanceUuid
$vcDisplayName = $servInst.Content.About.Name
$vcLicKey = ($licMgr.Licenses | where {$_.Name -eq $vcLicName}).LicenseKey
$licInfo = $licAssignMgr.UpdateAssignedLicense($vcUuid, $vcLicKey,$vcDisplayName)

# Show the properties of the VC license
$licInfo.Properties | % {
$licFeat = $_
$licFeat.Value | % {
Write-Host $_.Key $_.Value
Write-Host $licFeat.Key $licFeat.Value


Line 1: official name of the vCenter. Used to look up the license key.

Line 5: the InstanceUuid is the entity ID for the VC.

Line 7: fetch the VC license that is already loaded with the AddLicense method.

Line 10-23: displays on the console the product name, the product version and all the features.

  1. iliya
    August 28th, 2014 at 15:01 | #1

    Hi LucD
    Thanks for the entityID solution’but i have still one issue to solve:
    first i add the licence with addlicense call and this works fine’
    then i call to updateassignedlicense in order to set is as a current licence but it’s not affecting when i open the vshere client i see two licenses and the old one i assigned.

  2. Michael Scott
    April 26th, 2010 at 16:57 | #2

    LucD, Thanks again for your help.

    I found a way to make this work. I know this code is a little dirty, but I was in a hurry and was using multiple sources as a reference. This is the code that I am using:

    IF ($NTPhs.Config.Product.Version -lt “4.0.0”) {
    ELSE {
    $vcLicName = “vSphere 4 Enterprise”
    $targethostMoRef = (get-VMHost $ESXHost.Name | get-view).MoRef
    $si = Get-View ServiceInstance
    $LicManRef = $si.Content.LicenseManager
    $LicManView = Get-View $LicManRef
    $licAssMan = Get-View $LicManView.LicenseAssignmentManager
    $LicenseMan = Get-View $si.Content.LicenseManager
    $licGetMan = Get-View $LicenseMan.LicenseAssignmentManager
    $LicUse = $licGetMan.QueryAssignedLicenses($targethostMoRef.value)
    $LicKey = ($LicUse | % {$_.AssignedLicense}).LicenseKey
    $LicName = ($LicUse | % {$_.AssignedLicense}).Name

    if ($LicName -eq “Evaluation Mode”) {

    $LicFound = 0
    foreach ($LicKey in $LicManView.Licenses){
    if ($LicKey.Name -eq $vcLicName){
    if (($LicKey.Total – $LicKey.Used) -ge ($ESXHostview.Summary.Hardware.NumCpuPkgs)){
    $LicFound = 1
    Break # Only for the First License Found
    if ($LicFound -eq 0){
    [System.Windows.Forms.MessageBox]::Show(“A vSphere Host License could not be found, you may not have enough licenses available to satisfy the license request of this host.”)

  3. Michael Scott
    April 22nd, 2010 at 20:31 | #3


    I tried this but it did not work. The updateassignedlicense method removes all current licenses and then adds one license. I am trying to find a way to specify that the host should be assigned two licenses.

    do you have any other ideas? Thanks again for your help!

    • April 23rd, 2010 at 07:29 | #4

      Hi Michael, I have limited web access till Monday.
      Can you hold on for a couple of days ?

  4. Michael Scott
    April 22nd, 2010 at 03:06 | #5

    I am trying to use the script you are using as an example, but I have modified it a bit. It seems to assign a sing per processor license, but I have to sockets in use on the ESX server. How do I specify that I want 2 licenses assigned to this vSphere host? Any recommendations?

    My version of the script:

    $vcLicName = “vSphere 4 Enterprise”
    $servInst = Get-View ServiceInstance
    $licMgr = Get-View $servInst.Content.licenseManager
    $licAssignMgr = Get-View $licMgr.licenseAssignmentManager
    $ESXUuid = $ESXHostView.Summary.Hardware.Uuid
    foreach ($LicKey in $licMgr.Licenses){
    if ($LicKey.Name -eq “vSphere 4 Enterprise”){
    if (($LicKey.Total – $LicKey.Used) -ge ($ESXHostview.Summary.Hardware.NumCpuPkgs)){
    $licInfo = $licAssignMgr.UpdateAssignedLicense($ESXUuid, $LicKey.LicenseKey, $ESXHost.Name)
    Break # Only for the First License Found

    • April 22nd, 2010 at 06:58 | #6

      Michael, Can’t you call the UpdateAssignedLicense method in a foreach loop over all the processor blocks ?
      Something like this

      $licInfo = $licAssignMgr.UpdateAssignedLicense($ESXUuid, $LicKey.LicenseKey, $ESXHost.Name)

      Of course provided the license in $LicKey.Name has enough free licenses left.

  5. October 29th, 2009 at 22:08 | #7

    I came out with a very similar set of PS to set the license for an ESX host.

    $targethostMoRef = (get-VMHost $esxhost | get-view).MoRef
    $si = Get-View ServiceInstance
    $LicManRef = $si.Content.LicenseManager
    $LicManView = Get-View $LicManRef
    $esxLicense = $LicManView.Licenses | where {$_.EditionKey -eq “esxEnterprise”}
    $licassman = Get-View $LicManView.LicenseAssignmentManager

    • October 29th, 2009 at 22:16 | #8

      Yes, the script for a VC license is practically the same but it was the entity ID that caused the problem in the case of a VC.
      Thanks for including your code.

  1. February 19th, 2011 at 16:46 | #1
  2. January 6th, 2012 at 00:49 | #2
  3. March 29th, 2012 at 19:32 | #3