Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

!deploy New Version #15

Merged
merged 6 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 147 additions & 0 deletions src/Public/Add-ProductStates.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
function Add-ProductStates {
<#
.SYNOPSIS
Adds statuses to a product PSObject.

.DESCRIPTION
Adds statuses to a product PSObject. If this function is used
in a command pipeline it will add properties to the resulting PSObject containing boolean properties. These properties reflect
status of Product Enablement and if it is updated. These values are calculated using the State DWORD using bitfields.

.PARAMETER ProductState
The value (DWORD) containing the bitflags.

.PARAMETER Products
PSObject containing object array of Microsoft.Management.Infrastructure.CimInstance#ROOT/SecurityCenter2/AntiVirusProduct

.EXAMPLE
PS C:\Users\maurice> Get-CimInstance -Namespace root/SecurityCenter2 -ClassName AntivirusProduct | Add-ProductStates

enabled : True
displayName : Trend Micro Antivirus+
instanceGuid : {AFEE279F-FAE7-BAEE-3A88-4BF7277B8551}
pathToSignedProductExe : C:\Program Files\Trend Micro\Titanium\TmWscSvc\wschandler.exe
pathToSignedReportingExe : C:\Program Files\Trend Micro\Titanium\TmWscSvc\WSCStatusController.exe
productState : 266240
timestamp : Sun, 12 Apr 2020 15:09:56 GMT
PSComputerName :

enabled : True
displayName : Sophos Home
instanceGuid : {FFADE7EA-DC92-4602-D6B2-626CD3450A0F}
pathToSignedProductExe : C:\Program Files (x86)\Sophos\Sophos Anti-Virus\WSCClient.exe
pathToSignedReportingExe : C:\Program Files (x86)\Sophos\Sophos Anti-Virus\WSCClient.exe
productState : 331776
timestamp : Sun, 12 Apr 2020 15:18:39 GMT
PSComputerName :

enabled : False
displayName : Windows Defender
instanceGuid : {D68DDC3A-831F-4fae-9E44-DA132C1ACF46}
pathToSignedProductExe : windowsdefender://
pathToSignedReportingExe : %ProgramFiles%\Windows Defender\MsMpeng.exe
productState : 393472
timestamp : Sun, 12 Apr 2020 15:08:57 GMT
PSComputerName :

.EXAMPLE
PS C:\Users\maurice> $products = Get-CimInstance -Namespace root/SecurityCenter2 -ClassName AntivirusProduct
PS C:\Users\maurice> Add-ProductStates -Products $products

enabled : True
displayName : Trend Micro Antivirus+
instanceGuid : {AFEE279F-FAE7-BAEE-3A88-4BF7277B8551}
pathToSignedProductExe : C:\Program Files\Trend Micro\Titanium\TmWscSvc\wschandler.exe
pathToSignedReportingExe : C:\Program Files\Trend Micro\Titanium\TmWscSvc\WSCStatusController.exe
productState : 266240
timestamp : Sun, 12 Apr 2020 15:09:56 GMT
PSComputerName :

enabled : True
displayName : Sophos Home
instanceGuid : {FFADE7EA-DC92-4602-D6B2-626CD3450A0F}
pathToSignedProductExe : C:\Program Files (x86)\Sophos\Sophos Anti-Virus\WSCClient.exe
pathToSignedReportingExe : C:\Program Files (x86)\Sophos\Sophos Anti-Virus\WSCClient.exe
productState : 331776
timestamp : Sun, 12 Apr 2020 15:18:39 GMT
PSComputerName :

enabled : False
displayName : Windows Defender
instanceGuid : {D68DDC3A-831F-4fae-9E44-DA132C1ACF46}
pathToSignedProductExe : windowsdefender://
pathToSignedReportingExe : %ProgramFiles%\Windows Defender\MsMpeng.exe
productState : 393472
timestamp : Sun, 12 Apr 2020 15:08:57 GMT
PSComputerName :

.EXAMPLE
PS C:\Users\maurice> (Get-CimInstance -Namespace root/SecurityCenter2 -ClassName AntivirusProduct)[0].productState | Add-ProductStates

enabled : True

.EXAMPLE
PS C:\Users\maurice> $prodState = (Get-CimInstance -Namespace root/SecurityCenter2 -ClassName AntivirusProduct)[0].productState
PS C:\Users\maurice> Add-ProductStates -ProductState $prodState

enabled : True

.NOTES
This function utilizes Test-IsProductEnabled, ... To enrich information on State.
#>
[CmdletBinding()]
param (
# This parameter can be passed from pipeline and can contain and array of collections that contain State or productstate members
[Parameter(ValueFromPipeline)]
[Microsoft.Management.Infrastructure.CimInstance[]]
$Products,
# Product State contains a value (DWORD) that contains multiple bitflags and we use the productState flag (0000F000)
[Parameter(Position = 0, ValueFromPipelineByPropertyName, ValueFromPipeline, HelpMessage = "The value (DWORD) containing the bitflags.")]
[Alias("STATE")]
[UInt32]$ProductState
)

begin {
$results = $null
}

process {
If ($Products -is [array]) {
If ($Products.Count -gt 0) {
If (Get-Member -inputobject $Products[0] -name "productState" -Membertype Properties) {
$results += $Products.PSObject.Copy()
foreach ($item in $Products) {
If($results.Where({$_.instanceGuid -eq $item.instanceGuid}).Properties.name -notmatch "state") {
$results.Where({$_.instanceGuid -eq $item.instanceGuid}) |
Add-Member -NotePropertyName state -NotePropertyValue $([ProductState]($item.productState -band [ProductFlags]::ProductState))
}
else {
Write-Error 'Could not add state property it already exists...'
}
If($results.Where({$_.instanceGuid -eq $item.instanceGuid}).Properties.name -notmatch "signatureStatus") {
$results.Where({$_.instanceGuid -eq $item.instanceGuid}) |
Add-Member -NotePropertyName signatureStatus -NotePropertyValue $([SignatureStatus]($item.productState -band [ProductFlags]::SignatureStatus))
}
else {
Write-Error 'Could not add signatureStatus property it already exists...'
}
}
}
}
}
If ($ProductState -and (-not $Products)) {
If($results.Properties.name -notmatch "enabled") {
$results += New-Object PSObject -Property @{
state = $([ProductState]($item.productState -band [ProductFlags]::ProductState))
signatureStatus = $([SignatureStatus]($item.productState -band [ProductFlags]::SignatureStatus))
}
}
}
}

end {
If($results) {
return $results
}
}
}
46 changes: 0 additions & 46 deletions src/Public/Test-IsProductEnabled.ps1

This file was deleted.

50 changes: 50 additions & 0 deletions src/Public/Test-IsProductStateOn.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
function Test-IsProductStateOn {
<#
.SYNOPSIS
Tests if given product state has product state flag to On
.DESCRIPTION
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.
.EXAMPLE
PS C:\> Test-IsProductStateOn -ProductState 393472
False
This example shows basic functionality
.OUTPUTS
Bool
.NOTES
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)
#>
[CmdletBinding()]
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.")]
[Alias("STATE")]
[UInt32]$ProductState
)

try
{
if( $([ProductState]::On -and $($ProductState -band [ProductFlags]::ProductState) ) )
{
return $true
}
else
{
return $false
}
}
catch
{
return $false
}
}
6 changes: 6 additions & 0 deletions src/enums/ProductFlags.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Flags()] enum ProductFlags
{
SignatureStatus = 0x000000F0
ProductOwner = 0x00000F00
ProductState = 0x0000F000
}
5 changes: 5 additions & 0 deletions src/enums/ProductOwner.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Flags()] enum ProductOwner
{
NonMs = 0x000
Windows = 0x100
}
7 changes: 7 additions & 0 deletions src/enums/ProductState.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Flags()] enum ProductState
{
Off = 0x0000
On = 0x1000
Snoozed = 0x2000
Expired = 0x3000
}
5 changes: 5 additions & 0 deletions src/enums/SignatureStatus.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Flags()] enum SignatureStatus
{
UpToDate = 0x00
OutOfDate = 0x10
}
10 changes: 7 additions & 3 deletions src/wrt.helpers.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# Version number of this module.

ModuleVersion = '1.0.3'
ModuleVersion = '1.0.8'

# Supported PSEditions
CompatiblePSEditions = 'Core', 'Desktop'
Expand Down Expand Up @@ -77,10 +77,13 @@

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @(
'Add-ProductStates'
'Deploy-CompressedFile',
'Deploy-File',
'Find-File',
'Remove-RegistryKey',
'Remove-RegistryValue',
'Search-Registry',
'Send-MessageToLocalUsers',
'Send-ToLogAnalytics',
'Test-IsProductEnabled',
Expand Down Expand Up @@ -111,7 +114,8 @@
# Tags applied to this module. These help with module discovery in online galleries.
Tags = @(
'helper',
'productstate'
'productstate',
'registry'
)

# A URL to the license for this module.
Expand All @@ -124,7 +128,7 @@
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = 'First release'
ReleaseNotes = 'Added Resolve-ProductState'

} # End of PSData hashtable

Expand Down