VMware Cloud Community
Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

VCenter assign license key - Powershell script

Hi

Quick question (hopefully)

I'm trying to assign License to Vcenter with powershell script.

I'm able to get the license with this:

$vc = Connect-VIServer $vCenter -User $vCUser -Password $vCPW -Force -Verbose
$viewLicMgr = Get-View $vc.ExtensionData.Content.LicenseManager -Property Licenses
$license = $viewLicMgr.Licenses | ?{$_.EditionKey -like "vc.standard.instance"}

 but not quite able to change\assign a new license to the vcenter.

tried to use this - https://docs.vmware.com/en/VMware-vSphere/6.5/com.vmware.vsphere.install.doc/GUID-48AEE987-B2AC-432A...

but without success.

could you help me out adding onto my script, a part that change\assign new license? 

Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can use the AddLicense method

$licKey = '11111-22222-33333-44444-55555'

$licMgr = Get-View LicenseManager
$licMgr.AddLicense($licKey, $null)

$lic = $licMgr.Licenses.Where{ $_.EditionKey -eq 'vc.standard.instance' }
$licAssMgr = Get-View $licMgr.LicenseAssignmentManager

$licAssMgr.UpdateAssignedLicense($global:DefaultVIServer.InstanceUuid, $lic.LicenseKey, $global:defaultVIServer.Name)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

Assuming that the license is already added in the vCenter, you could try with

$licMgr = Get-View LicenseManager
$lic = $licMgr.Licenses.Where{ $_.EditionKey -eq 'vc.standard.instance' }
$licAssMgr = Get-View $licMgr.LicenseAssignmentManager

$licAssMgr.UpdateAssignedLicense($global:DefaultVIServer.InstanceUuid, $lic.LicenseKey, $global:defaultVIServer.Name)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

tnx for the reply

there is not license already added in the vcenter.

that is what I want to do with the script. to add a new and assign it.

just like for esxi host - Set-VMHost -LicenseKey ""

but for vcenter.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can use the AddLicense method

$licKey = '11111-22222-33333-44444-55555'

$licMgr = Get-View LicenseManager
$licMgr.AddLicense($licKey, $null)

$lic = $licMgr.Licenses.Where{ $_.EditionKey -eq 'vc.standard.instance' }
$licAssMgr = Get-View $licMgr.LicenseAssignmentManager

$licAssMgr.UpdateAssignedLicense($global:DefaultVIServer.InstanceUuid, $lic.LicenseKey, $global:defaultVIServer.Name)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

it prints out this: (with something looks like an error in the properties)

LicenseKey : 
EditionKey : 
Name       : 
Total      : 0
Used       : 
CostUnit   : 
Properties : {lc_error, localizedDiagnostic, diagnostic, Localized}
Labels     : 


LicenseKey : "Current License"
EditionKey : vc.standard.instance
Name       : vCenter Server 7 Standard
Total      : 1
Used       : 
CostUnit   : server
Properties : {ProductName, ProductVersion, FileVersion, feature...}
Labels     : 
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That 1st entry is the same error I get when I try to add an invalid key.
Are you sure you have a valid key in $licKey?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

you are correct sir. I tried to assign for the test, license of version 8 vc onto version 7.

but now that I'm trying to assign a correct license onto a VC with "Evaluation License"
I get another issue:

Exception calling "UpdateAssignedLicense" with "3" argument(s): "A specified parameter was not correct: entityId"

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you check that you only have 1 vCenter connection open?
One entry in $global:defaultVIServers


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Vlad_Belo
Enthusiast
Enthusiast
Jump to solution

oh yes it does show more than one entry. 

just restarted PSSessions and it worked.

Thanks!

Reply
0 Kudos