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
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
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
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.
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
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 :
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
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"
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
oh yes it does show more than one entry.
just restarted PSSessions and it worked.
Thanks!