Using PowerShell to Query WMI to Locate vSphere and AHV VMs!

Have you ever needed to quickly and easily locate all of the VMs in your domain? Recently I was involved in helping out some colleagues to determine which machines in a domain are either vSphere or AHV (Nutanix) based VMs. Microsoft makes it easy to locate Hyper-V based VMs with a simple dsquery command:

However, vSphere and AHV based machines are not quite this easy, so lets first examine an individual computer object.

From a command prompt run:

The results illustrate the System Manufacturer and System Model:

Image 001 – vSphere Virtual Machine

Image 002 – AHV (Nutanix) VM

With this information we can now utilize a few lines of simple PowerShell to query WMI on the local computer accounts to easily determine which objects are vSphere or AHV VMs.

If we take this one step further it is very easy loop through all objects within Active Directory and have the output sent to a .CSV file for further usage afterwards.

This example searches for the Model = “VMware Virtual Platform” – If you needed to search for all AHV based VMs just replace the search criteria with AHV. If you wanted to search for all Dell or HP model servers this PowerShell can be utilized too!

Wrap-Up

PowerShell to the rescue once again as we query WMI on individual computer objects to determine the Manufacturer and Model for VMware vSphere and Nutanix AHV! I hope you find this article to be useful.

Add a Comment

Your email address will not be published. Required fields are marked *