Skip to content

Instantly share code, notes, and snippets.

@gabriel-vanca
Last active July 23, 2024 15:21
Show Gist options
  • Save gabriel-vanca/fa5e96118b72b466b34a7f85455862aa to your computer and use it in GitHub Desktop.
Save gabriel-vanca/fa5e96118b72b466b34a7f85455862aa to your computer and use it in GitHub Desktop.
Windows License Info
<#
.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