Hyper-V, Hyper-V v2, PowerShell, Scripting, Virtualization
Leave a comment

Find all Hyper-V hosts and windows virtual machines in your AD environment

Several Microsoft products use Service Connection Points (SCP) to advertise themselves using objects stored in Active Directory. Clients query the directory to locate services. Microsoft Hyper-V, as I mentioned, also registers or publishes its information in AD as a service connection point. Now, we can use ADSI or AD cmdlets or Quest AD cmdlets to retrieve this information.

To retrieve a list of all “Hyper-V hosts” in the AD environment,

Using ADSI

Using Microsoft AD cmdlets

Using Quest AD cmdlets

The above methods retrieve the name of the computers running Hyper-V role.

To retrieve a list of all “Windows Virtual Machines” in the AD environment,

Using ADSI

Using Microsoft AD cmdlets

Using Quest AD cmdlets

This is it! If you observe the above code, I just changed the Name property alone to either “Microsoft Hyper-V” or “Windows Virtual Machine”. I tested the above commands only on Windows Server 2008 R2 and Windows Virtual machines only. I am not sure if Linux or other virtual machines running on Hyper-V get registered or not. I don’t have or need any of them in my setup 😉

Filed under: Hyper-V, Hyper-V v2, PowerShell, Scripting, Virtualization

by

Ravikanth is a principal engineer and the lead architect for Microsoft and VMware virtualized and hybrid cloud solutions within the Infrastructure Solutions Group at Dell EMC. He is a multi-year recipient of Microsoft Most Valuable Professional (MVP) award in Windows PowerShell (CDM) and Microsoft Azure. Ravikanth is the author of Windows PowerShell Desired State Configuration Revealed (Apress) and leads Bangalore PowerShell and Bangalore IT Pro user groups. He can be seen speaking regularly at local user group events and conferences in India and abroad.