共用方式為


Do you know what Virtual Server hosts are running in your domain? Find out how.

Wow. Can't believe it's close to 3 months since posting - just shows how busy life can get sometimes. Anyway, I thought I'd share this script which will tell you how many domain-joined Virtual Server hosts are currently running in your organization. It takes advantage of the SCP (Service Connection Point) marker in Active Directory which was introduced in Virtual Server 2005 R2 SP1 (currently in Beta - not too much longer to wait before release).

 On Error Resume Next
 Const SCP = "MS Virtual Server"
  
 ' 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
        

Either download a text file with the contents here and rename it, or copy the above code into a file "FindServers.vbs". Edit the call to "DoQuery" at the top to put in the appropriate domains for your organization. If you want a list of the machine names as well, uncomment the code-block starting "oRecordSet.MoveFirst" and ending "Loop". To run the script, from a command-line, type "cscript FindServers.vbs".

Cheers,

John.

Comments

  • Anonymous
    January 01, 2003
    Another new feature of Virtual Server 2005 R2 SP1 is that it now has an Active Directory marker that

  • Anonymous
    January 01, 2003
    I seems an eternity ago (May 2007) that I put up a post describing how to determine which domain-joined

  • Anonymous
    January 01, 2003
    John Howard, Program Manager for Microsoft Windows Virtualization, shares this script which will tell you how many domain-joined Virtual Server hosts are currently running in your organization. It takes advantage of the SCP (Service Connection Point)

  • Anonymous
    January 01, 2003
    Another new feature of Virtual Server 2005 R2 SP1 is that it now has an Active Directory marker that

  • Anonymous
    January 01, 2003
    I enjoyed some Out Of Office days to spent some time in the garden, catching up with some friends and

  • Anonymous
    July 01, 2007
    John, your site was one of the ones I used to go to all the time but since you started in the States, it seems the regular dose of favorite info has dwindled far in between.  Hope they pay you to do more postings as you provided technical clarity and incentive for people to look at MS based solutions.  For example, your ISCSI and VS based clustering was one of the first for everyone to be based off from...  there are alot more we miss...

  • Anonymous
    July 23, 2007
    Nice script. I re-wrote it with PowerShell. See the script at http://msgoodies.blogspot.com/2007/07/finding-virtual-servers-in-domain.html