Created
January 16, 2018 16:59
-
-
Save tvories/eb3be277543833b2f8c2b7f8aadcd263 to your computer and use it in GitHub Desktop.
Get-ActivationStatus - Gets activation status for Windows machine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-ActivationStatus { | |
[CmdletBinding()] | |
param( | |
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] | |
[string]$ComputerName = $Env:COMPUTERNAME, | |
[System.Management.Automation.CredentialAttribute()]$Credential | |
) | |
process { | |
try { | |
# Load CimInstance in Server2003 Compatability Mode | |
$CimSessionOption = New-CimSessionOption -Protocol Dcom | |
$CimSession = New-CimSession -SessionOption $CimSessionOption -ComputerName $ComputerName -Credential $Credential | |
$wpa = Get-CimInstance -classname SoftwareLicensingProduct -CIMSession $CimSession ` | |
-Filter "ApplicationID = '55c92734-d682-4d71-983e-d6ec3f16059f'" ` | |
-Property LicenseStatus -ErrorAction Stop | |
} catch { | |
$status = New-Object ComponentModel.Win32Exception ($_.Exception.ErrorCode) | |
$wpa = $null | |
} | |
$out = New-Object psobject -Property @{ | |
ComputerName = $ComputerName; | |
Status = [string]::Empty; | |
} | |
if ($wpa) { | |
:outer foreach($item in $wpa) { | |
switch ($item.LicenseStatus) { | |
0 {$out.Status = "Unlicensed"} | |
1 {$out.Status = "Licensed"; break outer} | |
2 {$out.Status = "Out-Of-Box Grace Period"; break outer} | |
3 {$out.Status = "Out-Of-Tolerance Grace Period"; break outer} | |
4 {$out.Status = "Non-Genuine Grace Period"; break outer} | |
5 {$out.Status = "Notification"; break outer} | |
6 {$out.Status = "Extended Grace"; break outer} | |
default {$out.Status = "Unknown value"} | |
} | |
} | |
} else {$out.Status = $status.Message} | |
$out | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment