WMI Filter to Check if Machine is a VM

WMI Scheme

In a world where virtualization is alway more prominent it is sometimes difficult to tell if the machine we are connected to is a physical or virtual machine and sometimes, especially when using scripts or applying GPOs, it can be handy to have a way to check if a machine is a VM for example to filter GPOs or even install packages only on VM as part of a sequence in OSD.

This is rather easily accomplished with the following WMI Query filter

#Check if VM

SELECT * FROM Win32_ComputerSystem  WHERE Model LIKE '%Virtual%'

The above query will work for both Hyper-V, which will return ‘Virtual Machine’, and VMware, which will return ‘VMware Virtual Platform’ as the model name

Check if VM GPO Filter

To apply the filter first of all create the GPO object and right-click on the WMI Filters node selecting New

GPO WMI Filter

In the New WMI Filter window insert a descriptive name for the filter and then click on the Add button where you can copy the WMI Query code above

Check if VM WMI Filter

[su_spoiler title=”Note for Windows 2012 R2″ style=”fancy”]

If you’re editing the WMI filter on a Windows 2012 R2 machine or Domain Controller you will probably get the error below

WMI Filter Error

If that’s the case just ignore it as the filter will work as intended, this is a bug with GPMC in Windows 2012 R2

[/su_spoiler]

Go back to the GPO object and in the WMI Filtering section select the WMI filter just created

Apply GPO WMI Filter

Now the GPO will only be applied to Virtual Machines.

Check if VM ConfigMgr OSD Task Sequence

I will take as an example a task sequence that will deploy VMware tools if the client being deployed is a VM to do this simply edit the Task Sequence and identify the step that will install VMware tools and go to the Options tab click on Add condition → Query WMI

SCCM Task Sequence WMI

Query WMI

Copy the code in the WQL Query are and hit the Test Query button to make sure code will be working and returning results

Test WMI Query

That’s it when using ConfigMgr to deploy the Operating system it will check if the machine is a VM and will install VMware tools as needed.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s