11 May 2007

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.

 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Scratch The Surface said:

I enjoyed some Out Of Office days to spent some time in the garden, catching up with some friends and

13 May 07 at 3:04 PM
# Lindley said:

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...

01 July 07 at 6:14 PM
# Noticias externas said:

Another new feature of Virtual Server 2005 R2 SP1 is that it now has an Active Directory marker that

13 July 07 at 2:32 AM
# VMblog.com - Virtualization Information said:

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)

13 July 07 at 9:13 AM
# Virtual PC Guy Blog said:

Another new feature of Virtual Server 2005 R2 SP1 is that it now has an Active Directory marker that

21 July 07 at 11:08 PM
# Per Østergaard said:

Nice script.

I re-wrote it with PowerShell.

See the script at http://msgoodies.blogspot.com/2007/07/finding-virtual-servers-in-domain.html

23 July 07 at 5:28 AM
# John Howard - Hyper-V and virtualization blog said:

I seems an eternity ago (May 2007) that I put up a post describing how to determine which domain-joined

30 June 08 at 4:25 PM

Leave a Comment

Comment Policy: No HTML allowed. URIs and line breaks are converted automatically. Your e–mail address will not show up on any public page.

(required) 
(optional)
(required) 

  
Enter Code Here: Required
Page view tracker