共用方式為


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. 
 DoQuery "DC=YOURDOMAIN,DC=com", "YOURDOMAIN", SCP
  
 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 
              'ADS_CHASE_REFERRALS_ALWAYS
     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: " & _
             szDomainDN
        exit sub
     End If
  
     If Not oRecordSet.EOF Then
        wscript.echo szDomainShortName & ":" & _
                     oRecordSet.RecordCount
  
        ' If you want to enumerate the machine names, 
        ' uncomment this block of code
        'oRecordSet.MoveFirst
        '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
        'Loop
     else
        wscript.echo szDomainShortName & ": 0"
     end if
  
     set oRecordSet = Nothing
     set oCommand = Nothing
     oConnection.Close
     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.

hypervusage

Cheers
John.

Comments

  • Anonymous
    January 01, 2003
    Great post, explained really well and I could really understand. Thank you.

  • Anonymous
    January 01, 2003
    One of the advantages of having Virtualization integrated with Windows is that the Hyper-V (and in fact

  • Anonymous
    January 01, 2003
    David - when the VMMS service starts, it should register the SCP automatically. Are there any errors in the Hyper-V-VMMS event log channel? Thanks, John.

  • Anonymous
    June 23, 2009
    The comment has been removed