I’m building some virtual machines for my demo’s at the upcoming PowerShell summit. To make the demo’s, and setup, more interesting(?) I decided to use some Server Core instances.
The usual setup activities become a bit more interesting with Server Core – particular Windows activation.
Windows 2012 R2 will activate itself if the new machine has an Internet connection when it is created. With the GUI version of Windows you can check that Windows is activated using the System applet in Control Panel.
If you’re using Server Core you can use WMI to test activation:
Get-CimInstance -ClassName SoftwareLicensingProduct |
where PartialProductKey |
select Name, ApplicationId, LicenseStatus |
Use the SoftwareLicensingProduct WMI class and filter for PartialProductkey – that means a product key has been entered. You can then select the name of the product the ApplicationId and the LicenseStatus:
Name : Windows(R), ServerStandard edition
ApplicationId : 55c92734-d682-4d71-983e-d6ec3f16059f
LicenseStatus : 1
A License status of 1 indicates that its licensed – i.e. activated
More on using WMI to test and set activation in chapter 13 of PowerShell and WMI – www.manning.com/siddaway2
I had to do a lot of activation and checking using Windows Server 2008 R2. I ended up using the Get-ActivationStatus cmdlet from http://social.technet.microsoft.com/wiki/contents/articles/5675.determine-windows-activation-status-with-powershell.aspx
#Check for activation on remote systems
Get-ADComputer -filter ‘samAccountName -like “vmgb*”‘ | Get-ActivationStatus
#Update key and activate (may stall out if executed remotely, so use ctrl+c to cancel or run a background job)
slmgr -ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX -ato
The function basically wraps what I showed in PowerShell and WMI.
I wouldn’t bother using slmgr to update the license key – use the SoftwareLincenseService class