WMI Query GPMC WMI Filter

WMI Filters for Group Policy to manage Windows Server versions

This post contains some example WMI filters for you to use in Group Policy Objects (GPOs) to target and manage specific Windows Server versions like 2012R2, 2016 and Windows Server 2019.

Using the Windows Management Infrastructure, or WMI, Windows admins can create filters to apply GPOs more granular on specific versions of Windows Server. In this post I provide some basic examples.

If you use PowerShell 5.1, you can verify WMI filters with Get-WmiObject in the Win32_OperatingSystem class:

PS C:\> Get-WmiObject -Class Win32_OperatingSystem | Select Version, ProductType
Code language: PowerShell (powershell)
PS C:\> Get-WmiObject -Class Win32_OperatingSystem | Select Version,Name,ProductType
Code language: PowerShell (powershell)

Selecting Name, it’s easy to select Windows Server 2012 R2. It’s recommended to use a LIKE sub-selection

Select Name From Win32_OperatingSystem Where Name Like '%Windows Server 2012 R2%'
Code language: PowerShell (powershell)

In a nutshell I’ll provide some easy to us WMI filter examples:

# Windows Server 2012 en 2016 by Name Select Name From Win32_OperatingSystem Where Name like '%Windows Server 2012 R2%' Or Name Like '%Windows Server 2016%'
Code language: PowerShell (powershell)
# Windows Server 2016 by Version Select Version From Win32_OperatingSystem Where Version Like "10.0.14%"
Code language: PowerShell (powershell)

Why did I use “Like “10.0.14%”“? Simply because Windows Server 2019’s version number also starts with 10.0. So by not adding .14 I’d also match Windows Server 2019:

# Windows Server 2016 en 2019 by Version Select Version From Win32_OperatingSystem Where Version Like "10.0%"
Code language: PowerShell (powershell)

And finally to only target Windows Server 2019:

# Windows Server 2019 by Version Select Version From Win32_OperatingSystem Where Version Like "10.0.17%"
Code language: PowerShell (powershell)

Match computer name in GPO WMI Filter

If you need to match a computer name in your GPO WMI Filter, you can use the following:

WMI Query match computer name in GPO WMI Filter
Select Name From Win32_ComputerSystem Where Name = "server name"
Code language: PostgreSQL SQL dialect and PL/pgSQL (pgsql)

Using this, an GPO is only applied if the computer -or server- name matches. Otherwise it is filtered out.

Get-WmiObject deprecated in PowerShell 6.2 and up

Note: in PowerShell 6.2 and up, the WMI v1 cmdlets, like Get-WmiObject, are deprecated. See Breaking Changes for PowerShell 6.x. You now have to use CIM (aka WIM v2), like for example Get-CimInstance.

PS C:\> Get-CimInstance -Class Win32_OperatingSystem | Select Version, ProductType Version ProductType ------- ----------- 10.0.17763 3
Code language: PowerShell (powershell)

WMI Filters conclusion

Using WMI filters like these in Group Policy Management Console, you can fine-tune your GPO targetting.

If needed, you can even query the hardware manufacturer in your script:

(Get-CimInstance -ClassName Win32_ComputerSystem).Manufacturer
Code language: PowerShell (powershell)
Sharing is caring

1 thought on “WMI Filters for Group Policy to manage Windows Server versions”

Comments are closed.

Mentions

Show Buttons
Hide Buttons