Hyper-V: Locate Hyper-V enabled servers in your domain

It seems an eternity ago (May 2007) that I put up a post describing how to determine which domain-joined servers are running Virtual Server in your domain(s). Well that same functionality is present in Hyper-V, only the SCP or “Service Connection Point” in Active Directory is different – “Microsoft Hyper-V“.

Here’s a sample VBScript code. Save the contents as “FindServers.vbs” (text file download) and run from an elevated command prompt “cscript FindServers.vbs”.

On Error Resume Next
Const SCP = “Microsoft Hyper-V”
‘ Add as many lines as needed for the domains in your org. 
Sub DoQuery(szDomainDN, szDomainShortName, szSCP)
    Set oConnection = CreateObject(“ADODB.Connection”)
    Set oCommand = CreateObject(“ADODB.Command”)
    oConnection.Provider = (“ADsDSOObject”)
    oConnection.Open “Ads Provider”
    oCommand.ActiveConnection = oConnection
    oCommand.Properties(“Page Size”) = 99
    oCommand.Properties(“Searchscope”) = &H2 ‘ADS_SCOPE_SUBTREE
    oCommand.Properties(“Chase Referrals”) = &H60 
    oCommand.CommandText = _
       “select distinguishedName from ‘LDAP://” & _
       szDomainDN & “‘ “ & _
       “where objectCategory=’serviceConnectionPoint’ “ & _
       “and cn='” & szSCP & “‘”
    Set oRecordSet = oCommand.Execute
    If Err Then
       wscript.echo _
           “ERROR: Unable to find Domain Rooted at: “ & _
       exit sub
    End If
    If Not oRecordSet.EOF Then
       wscript.echo szDomainShortName & “:” & _
       ‘ If you want to enumerate the machine names, 
       ‘ uncomment this block of code
       ‘Do Until oRecordSet.EOF
       ‘    szNodeName = _
       ‘      oRecordSet.Fields(“distinguishedName”)
       ‘    ‘Trim “CN=<szSCP>,CN=”
       ‘    szNodeName = _
       ‘      mid(szNodeName, InStr(szNodeName,”,CN=”)+4) 
       ‘    ‘Trim the domain DN
       ‘    szNodeName = _
       ‘      Left(szNodeName,InStr(szNodeName,”,”)-1)
       ‘    wscript.echo szNodeName
       ‘    oRecordSet.MoveNext
       wscript.echo szDomainShortName & “: 0”
    end if
    set oRecordSet = Nothing
    set oCommand = Nothing
    set oConnection = Nothing
End Sub

To use the script, edit the call right at the top to “DoQuery”, inserting the appropriate domain for your organisation. Add multiple lines if you have multiple domains. If you want a list of machine names, uncomment the code-block starting “oRecordSet.MoveFirst” and ending “Loop”

So I’m sure you’re wondering, how many servers are actively running at Microsoft? With a bit of additional work using the script as the starting point, a simple database and some Excel macro wizardry, I happen to have been tracking the stats internally for some time now. While I can’t share the scale, exact numbers and date-ranges for the graph below, you get an idea of the overall trend over a “few” months. (Don’t worry about why there’s two lines – the blue line is the important one). What I can say is that the current number is in the thousands. Many, many, thousands.



Comments (4)

  1. Anonymous says:

    Great post, explained really well and I could really understand. Thank you.

  2. Anonymous says:

    One of the advantages of having Virtualization integrated with Windows is that the Hyper-V (and in fact

  3. David – when the VMMS service starts, it should register the SCP automatically. Are there any errors in the Hyper-V-VMMS event log channel?



  4. David says:

    My hyper-v installation isn’t registered as a service connection point….  Anyway to tell it to register itself?  I’m on a 2008 domain with hyper-v on a 2008 box.