Automatically Clear assigned KMS Host on multiple KMS Clients and enable Auto-discovery

To do this we are going to utilize a small PowerShell script to remotely run a command to clear the assigned KMS host on multiple clients.

Doing this will remove the manual KMS Host entry and re-enable auto-discovery.

Normally if your clients are pointing to a dead KMS host you will notice that you can’t activate them again in VAMT (Volume Activation Management Tool), you will receive either error : Operation Timed Out or Unable to connect to the remote server.

What the script does –
It takes a list of host names from a CSV, then runs the clear KMS cache command (slmgr.vbs /ckms) on each server listed, this will force the KMS client to auto-discover a new KMS Host on the subnet. You can change the script to manually set a different specific KMS host by using the – slmgr.vbs /skms <value>:<port> instead of slmgr.vbs /ckms.

Script / CSV Example / Script Results –

$Servers = Get-Content C:\Temp\Book1.csv #Gets Hostnames from CSV

$Servers = $Servers[1..($Servers.count - 1)] #Removes Header

$UserCredential = Get-Credential #prompt for creddentials

#Removes the currently set KMS host on each KMS Client in the CSV and sets it to auto discovery
ForEach ($server in $Servers) {

Invoke-Command -ComputerName $server -ScriptBlock {Invoke-Expression "cscript c:\windows\system32\slmgr.vbs /ckms"}  -credential $UserCredential
}

 

Excel hostnameKey Management Service machine name cleared successfully

Hope this is helpful – feel free to change the slmgr.vbs command in the script if you want to utilize a different command on multiple servers/workstations.

 

 


Thanks for reading – feel free to follow and stay updated 🙂  View sysadminguides’s profile on Facebook View GuidesSysadmin’s profile on Twitter View 115372466162675927272’s profile on Google+

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s