< Back

New-GPWmiFilter

Tue Jan 14, 2020 12:16 am

NAME New-GPWmiFilter



SYNOPSIS

Create a new WMI filter for Group Policy with given name, WQL query and description.





SYNTAX

New-GPWmiFilter [-Name] <String> [-Filter] <String[]> [-Description <String>] [-Server <String>] [-Credential

<PSCredential>] [-EnableException] [-WhatIf] [-Confirm] [<CommonParameters>]





DESCRIPTION

The New-GPWmiFilter function create an AD object for WMI filter with specific name, WQL query expressions and

description.

With -PassThru switch, it output the WMIFilter instance which can be assigned to GPO.WMIFilter property.





PARAMETERS

-Name <String>

The name of new WMI filter.



Required? true

Position? 1

Default value

Accept pipeline input? true (ByPropertyName)

Accept wildcard characters? false



-Filter <String[]>

The wmi filter query to use as condition for the filter.



Required? true

Position? 2

Default value

Accept pipeline input? true (ByPropertyName)

Accept wildcard characters? false



-Description <String>

The description text of the WMI filter (optional).



Required? false

Position? named

Default value

Accept pipeline input? true (ByPropertyName)

Accept wildcard characters? false



-Server <String>

The server to contact.

Specify the DNS Name of a Domain Controller.



Required? false

Position? named

Default value $env:USERDNSDOMAIN

Accept pipeline input? false

Accept wildcard characters? false



-Credential <PSCredential>

The credentials to use to contact the targeted server.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-EnableException [<SwitchParameter>]

This parameters disables user-friendly warnings and enables the throwing of exceptions.

This is less user friendly, but allows catching exceptions in calling scripts.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-WhatIf [<SwitchParameter>]

If this switch is enabled, no actions are performed but informational messages will be displayed that explain

what would happen if the command were to run.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Confirm [<SwitchParameter>]

If this switch is enabled, you will be prompted for confirmation before executing any operations that change

state.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>New-GPWmiFilter -Name 'Virtual Machines' -Filter 'SELECT * FROM Win32_ComputerSystem WHERE Model = "Virtual

Machine"' -Description 'Only apply on virtual machines'



Create a WMI filter to apply GPO only on virtual machines









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Get-GPWmiFilter -Server contoso.com | New-GPWmiFilter -Server fabrikam.com



Copies all WMI Filters from the domain contoso.com to the domain fabrikam.com









-------------------------- EXAMPLE 3 --------------------------



PS C:\\>$filter = New-GPWmiFilter -Name 'Workstation 32-bit' -Expression 'SELECT * FROM WIN32_OperatingSystem WHERE

ProductType=1', 'SELECT * FROM Win32_Processor WHERE AddressWidth = "32"' -PassThru



$gpo = New-GPO -Name "Test GPO"

$gpo.WmiFilter = $filter



Create a WMI filter for 32-bit work station and link it to a new GPO named "Test GPO".











RELATED LINKS