VMware Cloud Community
cgrjones
Contributor
Contributor
Jump to solution

Basic VSphere License Key Install via PowerCLI Script

Hi all,

With the help of the community I was able to piece together a build script for ESXi 3.5 (basic/free edition). This script works fine with ESXi 4 (VSphere) but I am stuck on the section that completes the License Key install.

The orgional code segment for ESXi 3.5 was this:

$ESXHost=Get-VMHost

$ESXHostView=$ESXHost | Get-View

$ESXHostView

$ServiceInstance=Get-View -Server $ESXConnect ServiceInstance

$ServiceInstance.Content

$LicManRef=$ServiceInstance.Content.LicenseManager

$LicManView=Get-View -Server $ESXConnect $LicManRef

$LicServerSource=New-Object VMWARE.VIM.LocalLicenseSource

$LicServerSource.LicenseKeys="11111-AAAAA-BBBBB-CCCCC-DDDDD "

$LicManView.SetLicenseEdition($ESXHostView.MoRef,"")

$LicManView.ConfigureLicenseSource($ESXHostView.MoRef,$LicServerSource)

...but now the licensing system has changed we need to do something else. I have checked the new API v4.0 Reference and it has pointed me to where I can find the key but I dont know enough to get it to automatically assign.

Source :

SourceAvailable : False

Diagnostics :

FeatureInfo : {}

LicensedEdition :

Licenses : {ESXi 4 Single Server}

LicenseAssignmentManager :

Evaluation : VMware.Vim.LicenseManagerEvaluationInfo

MoRef : VMware.Vim.ManagedObjectReference

Client : VMware.Vim.VimClient

LicenseKey : 11111-AAAAA-BBBBB-CCCCC-DDDDD (my basic v4 key)

EditionKey : esxBasic

Name : ESXi 4 Single Server

Total : 0

Used : 1

CostUnit : cpuPackage:6core

Properties : {ProductName, ProductVersion, feature, feature...}

Labels :

DynamicType :

DynamicProperty :

Any help on this will be greatly appreciated Smiley Happy

Thanks

Chris

0 Kudos
1 Solution

Accepted Solutions
DougBaer
Commander
Commander
Jump to solution

Learn something new everyday!

$h = get-vmhost
$hv = $h | get-view
$si = Get-View ServiceInstance

$LicManRef=$si.Content.LicenseManager
$LicManView=Get-View $LicManRef

$license = New-Object VMware.Vim.LicenseManagerLicenseInfo
$license.LicenseKey = "YOUR LICENSE HERE"
$license.EditionKey="esxBasic"
$LicManView.UpdateLicense($license.LicenseKey,$null)

Doug Baer, Solution Architect, Advanced Services, Broadcom | VCDX #019, vExpert 2012-23

View solution in original post

0 Kudos
4 Replies
DougBaer
Commander
Commander
Jump to solution

I think this might actually be simpler. There is a new AddLicense method on the LicenseManager that seems to take the license key as a parameter (licenseKey).

Try this:

$h = get-vmhost
$hv = $h | get-view

$svcRef = New-Object VMware.Vim.ManagedObjectReference
$svcRef.Type = “ServiceInstance”
$svcRef.Value = “ServiceInstance”
$serviceInstance = Get-View $svcRef

$LicManRef=$ServiceInstance.Content.LicenseManager
$LicManView=Get-View $LicManRef

$license = New-Object VMware.Vim.LicenseManagerLicenseInfo
$license.LicenseKey = "YOUR LICENSE HERE"
$license.EditionKey="esxBasic"
$LicManView.UpdateLicense($license.LicenseKey,$null)

Doug Baer, Solution Architect, Advanced Services, Broadcom | VCDX #019, vExpert 2012-23
admin
Immortal
Immortal
Jump to solution

FYI you can just use

$si = Get-View ServiceInstance

DougBaer
Commander
Commander
Jump to solution

Learn something new everyday!

$h = get-vmhost
$hv = $h | get-view
$si = Get-View ServiceInstance

$LicManRef=$si.Content.LicenseManager
$LicManView=Get-View $LicManRef

$license = New-Object VMware.Vim.LicenseManagerLicenseInfo
$license.LicenseKey = "YOUR LICENSE HERE"
$license.EditionKey="esxBasic"
$LicManView.UpdateLicense($license.LicenseKey,$null)

Doug Baer, Solution Architect, Advanced Services, Broadcom | VCDX #019, vExpert 2012-23
0 Kudos
cgrjones
Contributor
Contributor
Jump to solution

Wow thanks for the quick reply Doug. Works perfectly.

0 Kudos