Created
July 28, 2022 11:16
-
-
Save pandieme/9b308c9bb73c0755528264bd9f4bc0b4 to your computer and use it in GitHub Desktop.
Get System WMI Filter in Active Directory. Used in Group Policy WMI Filtering.
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
function Get-SystemWmiFilter { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory, ValueFromPipeline)] | |
[string] | |
$Name, | |
[Parameter(Mandatory)] | |
[string] | |
$DomainName | |
) | |
$DomainDistinguishedName = "DC=" + $DomainName.Replace('.', ',DC=') | |
$Properties = @( | |
'msWMI-Author' | |
'msWMI-ID' | |
'msWMI-Name' | |
'msWMI-Parm1' | |
'msWMI-Parm2' | |
'Created' | |
'Modified' | |
) | |
$WmiFilter = Get-ADObject ` | |
-Filter { ObjectClass -eq "msWMI-Som" -and msWMI-Name -eq $Name } ` | |
-SearchBase "CN=SOM,CN=WMIPolicy,CN=System,$DomainDistinguishedName" ` | |
-SearchScope OneLevel ` | |
-Properties $Properties | |
$Response = [PSCustomObject]@{ | |
Id = $WmiFilter.'msWMI-ID'.Trim('{}') | |
Name = $WmiFilter.'msWMI-Name' | |
Description = $WmiFilter.'msWMI-Parm1' | |
Query = $WmiFilter.'msWMI-Parm2' | |
Author = $WmiFilter.'msWMI-Author' | |
Created = $WmiFilter.Created | |
Modified = $WmiFilter.Modified | |
} | |
return $Response | |
} |
Author
pandieme
commented
Jul 28, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment