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
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
[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
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
Go back to the GPO object and in the WMI Filtering section select the WMI filter just created
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
Copy the code in the WQL Query are and hit the Test Query button to make sure code will be working and returning results
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.