PowerShell Quick Tip 04 – Bulk Windows Activation

Posted: 10/01/2013 in Data Centre, PowerShell

Today I found myself in a situation where I needed to enter a product key and then activate several Windows 2008 R2 Servers, this would be a real chore if I had to use the GUI.

A quick internet search brought me to slmgr.vbs a great little script that has been included with Windows since Vista/2008 and it even works remotely. Looking at the options on the TechNet page you can see that a simple “slmgr.vbs ServerName -ipk “AAAAA-BBBBB-CCCCC-DDDDD-EEEEE””(Replace the latter with a valid product key) would sort the product key task out for me. To activate and complete the task I would need to use with the following command “slmgr.vbs ServerName –ato”, simple.

One of the tricks I find myself doing again and again from the PowerShell prompt is simple string manipulation, for example:

Get-VM LAB* | % { write "slmgr.vbs $($_.Name) -ipk `" AAAAA-BBBBB-CCCCC-DDDDD-EEEEE `" }

Would create something along the lines of:

slmgr.vbs LAB1-SQL-001 -ipk “AAAAA-BBBBB-CCCCC-DDDDD-EEEEE”
slmgr.vbs LAB1-DC-001 -ipk “AAAAA-BBBBB-CCCCC-DDDDD-EEEEE”
slmgr.vbs LAB1-EX-001 -ipk “AAAAA-BBBBB-CCCCC-DDDDD-EEEEE”

To save yourself even more time you can send the output of the above command directly to the clipboard by piping to “clip”, for example:

Get-VM LAB* | % { write "slmgr.vbs $($_.Name) -ipk `" AAAAA-BBBBB-CCCCC-DDDDD-EEEEE `" } | clip

This allows you to paste back into the console and execute your commands.

After each command executes you are presented with a pop up window like the one below

Activate-01

Now do the same for your activation command

Get-VM LAB* | % { write "slmgr.vbs $($_.Name) -ato" }  | clip

After each command executes you are again presented with another pop up window, this one will look like the one below

Activate-02

Admittedly this is a little quick and dirty and could do with some error checking but it got the job done and saved me a couple of hours work, hopefully it will save others time as well.

Thanks for reading.

jfrmilner

Advertisements
Comments
  1. Davy Crijns says:

    Hey JFRMILNER, you forgot a quote at the end :).

    Get-VM LAB* | % { write “slmgr.vbs $($_.Name) -ipk `” AAAAA-BBBBB-CCCCC-DDDDD-EEEEE `” “}

    And this should work for the servers in the same domain?

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