Skip to content

Instantly share code, notes, and snippets.

Last active April 13, 2020 12:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
function Test-IsProductStateOn {
Tests if given product state has product state flag to On
Registry, WMI and other properties may contain a DWORD value or data object that represents the state of the corresponding product.
Specific state of the product is set to a bit in this DWORD, these states can be optained using bitwise operations.
This function will return true if the flag for product state is set to on, meaning this product is enabled.
.PARAMETER ProductState
The value (DWORD) containing the bitflags.
PS C:\> Test-IsProductStateOn -ProductState 393472
This example shows basic functionality
This function was build to resolve the state of a Antivirus Provider registered in Security Center.
Using this function it is possible to read which product is set to On or not.
Other states are Off, Snoozed and Expired which can be resolved by using the enums provided in this module.
Example: Get-CimInstance -Namespace root/SecurityCenter2 -ClassName AntivirusProduct | Where-Object {($_.productState -band [ProductFlags]::ProductState) -eq [ProductState]::Off}
Will list all products that are disabled.
Use Add-ProductStates to return the actual state or cast the value using the stateflag
$prod = Get-CimInstance -Namespace root/SecurityCenter2 -ClassName AntivirusProduct
[SignatureStatus]($prod[0].productState -band [ProductFlags]::SignatureStatus)
param (
# Product State contains a value (DWORD) that contains multiple bitflags and we use the productState flag (0000F000)
[Parameter(Mandatory, Position = 0, ValueFromPipelineByPropertyName, HelpMessage = "The value (DWORD) containing the bitflags.")]
if( $([ProductState]::On -and $($ProductState -band [ProductFlags]::ProductState) ) )
return $true
return $false
return $false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment