I made a script that will output the current license keys per cluster and changes them to a new one which the script will ask for. Just make sure you have the license key already added to vCenter. The script will ask you for inputs so it should just work. But better to be safe then sorry and test it first!

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$vcenter = [Microsoft.VisualBasic.Interaction]::InputBox('Enter vCenter Name...', 'vCenter Name')
Connect-VIServer $vcenter

$cluster = Get-Cluster | Out-GridView -OutputMode Single -Title "Select Cluster"
$hosts = Get-Cluster $cluster | Get-VMHost | Sort-Object


foreach ($esxhost in $hosts){
    $currentkey = Get-VMHost $esxhost | Select LicenseKey
    Write-Host $esxhost License key is currently: $currentkey.LicenseKey -ForegroundColor Green
}

$newlicensekey = [Microsoft.VisualBasic.Interaction]::InputBox('New License Key', 'License Key')

foreach ($esxhost in $hosts){
    Set-VMHost -VMHost $esxhost -LicenseKey $newlicensekey
    Write-Host $esxhost License key set to $esxhost.LicenseKey -ForegroundColor Green
}

Disconnect-VIServer * -Confirm:$false
3 thoughts on “Change ESXi License Keys”
  1. Thanks Paul!

    What happens when you enter a invalid license key? For example due to a spelling error?

    Thanks,
    Henk

Leave a Reply

Your email address will not be published. Required fields are marked *