Skip to content

Instantly share code, notes, and snippets.

@paulschmeida
paulschmeida / Get-WindowsLicenseStatus.ps1
Created November 6, 2019 23:30
Comparison of filtering early and where-object while using Get-CimInstance
function Get-WindowsLicenseStatus {
$Filter = "Name like 'Windows%' and PartialProductKey like '%'"
$LicenseStatus = (Get-CimInstance SoftwareLicensingProduct -Filter $Filter -Property LicenseStatus).LicenseStatus
return "LicenseStatus=${LicenseStatus}"
}
$exp1 = {Get-WindowsLicenseStatus}
$exp2 = {Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" | where { $_.PartialProductKey } | select -ExpandProperty LicenseStatus | Write-Host}
# Available colors
# DarkBlue | DarkGreen | DarkCyan | DarkRed | DarkMagenta | DarkYellow |DarkGray
# Blue | Green | Cyan | Red | Magenta | Yellow | White | Gray | Black
# Main Colors
$host.UI.RawUI.ForegroundColor = 'White'
$host.UI.RawUI.BackgroundColor = 'DarkGray'