Virtualization Technology News and Information
Article
RSS
CODE: Find out Which Virtual Server Hosts are Running in your Domain

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) marker in Active Directory which was introduced in Virtual Server 2005 R2 SP1.

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

     'oRecordSet.MoveFirst

     'Do Until oRecordSet.EOF

     ' szNodeName = oRecordSet.Fields("distinguishedName")

     'szNodeName = Mid(szNodeName, InStr(szNodeName, ",CN=") + 4) ' Trim "CN=<szSCP>,CN="

     ' szNodeName = Left(szNodeName, InStr(szNodeName, ",") - 1) ' Trim the domain DN

     ' 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

Save the above script as "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".

Read and comment on the original, here.

Published Friday, July 13, 2007 6:05 AM by David Marshall
Filed under:
Comments
There are no comments for this post.
To post a comment, you must be a registered user. Registration is free and easy! Sign up now!
Calendar
<July 2007>
SuMoTuWeThFrSa
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234