Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


List Domain Controllers

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,33275
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> List Domain Controllers
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 List Domain Controllers - 4/8/2006 3:23:26 PM   
  DiGiTAL.SkReAM


Posts: 1146
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
I was writing a script for a client, and discovered that I needed a way to list all of the domain controllers in a domain, no matter if they had been moved out of the default OU or not.
I did some searching on Google, and came across the Scripting Guys way of listing them, modified it a bit, and came up with this function that you can just plug into your code:


      
EDIT: Added some error checking for times when a DC is not available.  The function will then return "N/A", which you can change to suit your own warped and twisted little worlds.

< Message edited by DiGiTAL.SkReAM -- 4/8/2006 3:46:38 PM >


_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury
 
 
Revisions: 2 | Post #: 1
 
 RE: List Domain Controllers - 4/10/2006 1:44:28 AM   
  hopsbarleyman

 

Posts: 9
Score: 0
Joined: 1/17/2006
Status: offline
That is a great piece of code to enumerate DC's. I wrote a quick script about a year ago that uses the nTDSDSA object you demonstrated in enumerating DC's within the forest,queries them for specific attributes, and sends the output to a formatted Excel spreadsheet. Thought I'd offer it up as a good starting example that can be easily modified to include/omiit other attributes as needed for reporting on different AD environments.

      

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 2
 
 RE: List Domain Controllers - 4/10/2006 1:48:49 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
It is just a pet peeve of mine and has no functional effect at all, but there is no point to putting WScript.Quit at the end of the script. As I said it is a personal thing and I have always maintained that if the script does what you want then it is by definition written correctly.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to hopsbarleyman)
 
 
Post #: 3
 
 RE: List Domain Controllers - 4/10/2006 2:20:37 AM   
  DiGiTAL.SkReAM


Posts: 1146
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
I just realized that my code requires my StringCat class.  So here it is:

      

_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to ebgreen)
 
 
Post #: 4
 
 RE: List Domain Controllers - 4/11/2006 4:51:19 AM   
  hopsbarleyman

 

Posts: 9
Score: 0
Joined: 1/17/2006
Status: offline
Yep, I agree. It's also not really necessary to release the instantiated objects from memory either. This was an old script I wrote a while back and this particular version was one I used in helping another admin who was new to scripting learn proper form and demonstrate releasing objects from memory. It is some extra fluff that's unnecessary, I just didn't take it out before posting.

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: List Domain Controllers - 4/13/2006 12:55:33 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
I thought I'd throw in my (modified scripting guy script as well!) domain controller role script as well 

'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.0
'
' NAME: getadroles.vbs
'
' AUTHOR: Kirrilian
' DATE  : 11/3/2005
'
' COMMENT: just run it, preferably with cscript :)
'            code liberally hacked/borrowed from the script repository
'==========================================================================
'put your domains in below
domains = Array("domain1", "domain2", "domain3", "domain4")

For Each domain In domains
   WScript.Echo "*********** Querying: " & domain & " *************"
   getdomaininfo domain
   WScript.echo
Next

Sub getdomaininfo(domain)
   'needed for the gc queries
   On Error Resume Next
  
   Set objRootDSE = GetObject("LDAP://" & domain & "/rootDSE")
    
   'ugly code follows...
   Set objSchema = GetObject _
       ("LDAP://" & objRootDSE.Get("schemaNamingContext"))
   strSchemaMaster = objSchema.Get("fSMORoleOwner")
   Set objNtds = GetObject("LDAP://" & strSchemaMaster)
   Set objComputer = GetObject(objNtds.Parent)
   WScript.Echo "Forest-wide Schema Master FSMO: " & objComputer.Name
    
   Set objNtds = Nothing
   Set objComputer = Nothing
    
   Set objPartitions = GetObject("LDAP://CN=Partitions," & _
       objRootDSE.Get("configurationNamingContext"))
   strDomainNamingMaster = objPartitions.Get("fSMORoleOwner")
   Set objNtds = GetObject("LDAP://" & strDomainNamingMaster)
   Set objComputer = GetObject(objNtds.Parent)
   WScript.Echo "Forest-wide Domain Naming Master FSMO: " & objComputer.Name
    
   Set objDomain = GetObject _
       ("LDAP://" & objRootDSE.Get("defaultNamingContext"))
   strPdcEmulator = objDomain.Get("fSMORoleOwner")
   Set objNtds = GetObject("LDAP://" & strPdcEmulator)
   Set objComputer = GetObject(objNtds.Parent)
   WScript.Echo "Domain's PDC Emulator FSMO: " & objComputer.Name
    
   Set objRidManager = GetObject("LDAP://CN=RID Manager$,CN=System," & _
       objRootDSE.Get("defaultNamingContext"))
   strRidMaster = objRidManager.Get("fSMORoleOwner")
   Set objNtds = GetObject("LDAP://" & strRidMaster)
   Set objComputer = GetObject(objNtds.Parent)
   WScript.Echo "Domain's RID Master FSMO: " & objComputer.Name
    
   Set objInfrastructure = GetObject("LDAP://CN=Infrastructure," & _
       objRootDSE.Get("defaultNamingContext"))
   strInfrastructureMaster = objInfrastructure.Get("fSMORoleOwner")
   Set objNtds = GetObject("LDAP://" & strInfrastructureMaster)
   Set objComputer = GetObject(objNtds.Parent)
   WScript.Echo "Domain's Infrastructure Master FSMO: " & objComputer.Name
  
   'check for global catalogs
   Const NTDSDSA_OPT_IS_GC = 1
   Set objGC = GetObject("LDAP://OU=Domain Controllers," & _
       objRootDSE.Get("defaultNamingContext"))
   For Each gc In objGC
       'clean up the ldap response
       gc = Replace(gc.name, "CN=", "")
       Set objRootDSE = GetObject("LDAP://" & gc & "/rootDSE")
       strDsServiceDN = objRootDSE.Get("dsServiceName")
       Set objDsRoot  = GetObject("LDAP://" & gc & "/" & strDsServiceDN)
       'this doesnt always exist therefore we have to use on error resume next
       intOptions = objDsRoot.Get("options")
       'check to see if the previous command failed with the err.number function
       If intOptions And NTDSDSA_OPT_IS_GC and err.Number = 0 Then
           WScript.Echo gc & " is a global catalog server."
       Else
           WScript.Echo gc & " isnt up or isnt a global catalog server."
           Err.Clear
       End If
   next

End Sub 'getdomaininfo
      

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to hopsbarleyman)
 
 
Post #: 6
 
 RE: List Domain Controllers - 4/17/2006 6:58:59 AM   
  johnrod

 

Posts: 9
Score: 0
Joined: 9/19/2005
Status: online
Hello--

Thanks for posting your script--    I was trying to use it however, it did not work correctly.   

When I removed "On Error Resume Next", it states that it cannot find the object objTextFile in line 51.   When I tried to resolve this, it kept coming up with more errors down the line.

Can you offer any assistance?

Thanks!
John

(in reply to hopsbarleyman)
 
 
Post #: 7
 
 RE: List Domain Controllers - 4/17/2006 7:04:41 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
You'll probably need to post the actual code that you are running since quite a bit has been posted in this thread.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to johnrod)
 
 
Post #: 8
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> List Domain Controllers Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts