VBScript for Domain Controllers
Hi!!! I dont know whether if this post is in the correct section, Ihavent found any section about windows 2003 or scripting. Ok, this is my question: I need a vbscript that can list the Domain Controllers in a domain, but only the domain that ill specify in a forest with multiple domains. AllDCs are Windows Servers 2003. Could you help me with this task? Thanks
May 26th, 2008 5:44pm

This script will do that, you'll need to edit the RED fields. Const ADS_SCOPE_SUBTREE = 2 Set objConnection = CreateObject("ADODB.Connection")Set objCommand = CreateObject("ADODB.Command")objConnection.Provider = "ADsDSOObject"objConnection.Open "Active Directory Provider"Set objCOmmand.ActiveConnection = objConnectionobjCommand.CommandText = _ "Select distinguishedName from " & _ "'LDAP://cn=Configuration,DC=fabrikam,DC=com' " _ & "where objectClass='nTDSDSA'" objCommand.Properties("Page Size") = 1000objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE Set objRecordSet = objCommand.ExecuteobjRecordSet.MoveFirstDo Until objRecordSet.EOF Wscript.Echo "Computer Name: " & _ objRecordSet.Fields("distinguishedName").Value objRecordSet.MoveNextLoop So if your domain is named mydomain.local it would be DC=mydomain,DC=local but if it's named ad.mydomain.local you'd have to add another DC= so the line would read DC=ad,DC=mydomain,DC=local
Free Windows Admin Tool Kit Click here and download it now
May 26th, 2008 5:58pm

Joachim thank for your anwser, My domain is subdomain.domain.net, so Ive done this script: Const ADS_SCOPE_SUBTREE = 2 Set objConnection = CreateObject("ADODB.Connection")Set objCommand = CreateObject("ADODB.Command")objConnection.Provider = "ADsDSOObject"objConnection.Open "Active Directory Provider"Set objCOmmand.ActiveConnection = objConnectionobjCommand.CommandText = _ "Select distinguishedName from " & _ "'LDAP://CN=Configuration,DC=SubDomain,DC=Domain,DC=net' " _ & "where objectClass='nTDSDSA'" objCommand.Properties("Page Size") = 1000objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE Set objRecordSet = objCommand.ExecuteobjRecordSet.MoveFirstDo Until objRecordSet.EOF Wscript.Echo "Computer Name: " & _ objRecordSet.Fields("distinguishedName").Value objRecordSet.MoveNextLoop But when I run this script It show methis error: Error: Table does not exist. Code: 80040E37 Source: Provider When I write only: "'LDAP://CN=Configuration,DC=Domain,DC=net' " _ then, dont show me any error and the script show me all the DCs in the forest. Why doesmy scripthave this behavior? Bye!
May 26th, 2008 7:21pm

You'll need to run the script from a domain controller in that particular domain. Otherwise the script will have to enumerate all the subdomains first and then enumerate the DC's in each domain, this is of course possible but this script won't do that.
Free Windows Admin Tool Kit Click here and download it now
May 26th, 2008 9:08pm

Hello, For your reference, if all domain controllers are in the default OU "Domain Controllers" you can simply list all computer accounts in that OU. ----------------------------------------------------Set objOU = GetObject(LDAP://ou=Domain Controllers, dc=subdomain, dc=domain, dc=net)objOU.Filter = Array(Computer)For Each objComputer in objOU Wscript.Echo objComputer.CNNext----------------------------------------------------
May 27th, 2008 9:11am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics