James O'Neill's Blog

June 30, 2008

Finding Hyper-V servers in your domain

Filed under: Powershell,Virtualization,Windows Server,Windows Server 2008 — jamesone111 @ 11:40 pm

One of the advantages of having Virtualization integrated with Windows is that the Hyper-V (and in fact Virtual Server 2005) registers itself in active directory so you can discover your servers easily – quite useful if servers start popping up like mushrooms. 

John Howard has been tracking the number of registered servers on the Microsoft corporate network for a while now, and he shared his VB script internally a little while ago, and has now posted it on his blog,

I’ve reworked it to run in PowerShell, and I got a shock when I found how many machines in my Domain were running HyperV. Lots

function get-vmHosts 

{param ($domain=([adsi]('GC://'+([adsi]'LDAP://RootDse').RootDomainNamingContext))) $searcher= New-Object directoryServices.DirectorySearcher($domain) $searcher.filter="(&(cn=Microsoft hyper-v)(objectCategory=serviceConnectionPoint))" $searcher.Findall()   | foreach {$_.path.split(",")[1].replace("CN=","")} }

#Example get-vmhosts  "DC=ite,DC=contoso,DC=com" | foreach {$_; list-vmstate -server $_} #                      Queries the domain ITE.Contoso.com for Hyper-V servers,
# prints the name of each and dumps the state of VMs on each

I’ve added this to the latest drop of my Hyper-V library which I will post to CodePlex towards the end of this week.

This post originally appeared on my technet blog.

Blog at WordPress.com.