PowerShell for Windows Admins

Jan 8 2014   12:47PM GMT

Test windows activation

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I’m currently upgrading my lab environment to Windows Server 2012 R2 which involves upgrading some machines and rebuilding the others.  One task in any build or upgrade situation is to make sure that Windows is activated.

Windows Server 2012 R2 will activate once an Internet connection is established. This can sometimes take a few minutes. Rather than keep checking in the GUI I wrote a little function to do the job for me:

function test-activation {
$slp = Get-CimInstance -ClassName SoftwareLicensingProduct -Filter “PartialProductKey LIKE ‘%'”
if ($slp.LicenseStatus -eq 1) {
return “$($slp.Name) on $env:COMPUTERNAME is activated”
}
else {
return “$($slp.Name) on $env:COMPUTERNAME is NOT activated”
}
}

This is based on technique 104 in PowerShell and WMI  – www.manning.com/siddaway2

Get-CimInstance  uses the SoftwareLicensingProduct class and filters on the PartialProductKey property. The filter only picks up those instances where the property has a value.

If the LicensesStatus property equals its activated otherwise it isn’t.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: