Last active
July 23, 2024 15:21
-
-
Save gabriel-vanca/fa5e96118b72b466b34a7f85455862aa to your computer and use it in GitHub Desktop.
Windows License Info
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
<# | |
.Synopsis | |
Get the license status of a Windows computer | |
.DESCRIPTION | |
Gets the license details via SLMGR.vbs /dlv | |
.EXAMPLE | |
Get-WindowsLicenseInfo | |
Returns the license details of the local computer | |
.EXAMPLE | |
Get-WindowsLicenseInfo -ComputerName computer01.domain.com | |
Returns the license details of the computer | |
#> | |
Function Get-WindowsLicenseInfo { | |
Param | |
( | |
[String] $ComputerName = $NULL, | |
[PSCredential] $Credential = $NULL | |
) | |
Process { | |
[ScriptBlock] $sbLicInfo = { | |
((cscript $env:windir\System32\slmgr.vbs /dlv | Select-Object -Skip 4) -replace ': ', '=') | | |
ConvertFrom-StringData -ErrorAction SilentlyContinue | |
} | |
If ($ComputerName) { | |
If ($Credential) { | |
Invoke-Command -ScriptBlock $sbLicInfoName -Credential $Credential ` | |
-Authentication Kerberos -ErrorAction SilentlyContinue | |
} | |
Else { | |
Invoke-Command -ScriptBlock $sbLicInfoName -ErrorAction SilentlyContinue | |
} | |
} | |
Else { | |
Invoke-Command -ScriptBlock $sbLicInfo | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment