Photo Gallery
Member List
Search
Calendars
FAQ
Ticket List
Log Out
Forums
Register
Login
My Profile
Inbox
Address Book
My Subscription
My Forums
get AD roles
Logged in as: Guest
arrSession:exec spGetSession 2,16,27711
Active Users: There are
0
members and
0
guests.
Users viewing this topic: none
Printable Version
All Forums
>>
[Scripting]
>>
Post a VBScript
>> get AD roles
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 >>
get AD roles -
11/3/2005 8:54:32 AM
kirrilian
Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status:
offline
This script queries the domains you specify to find the FSMO roles and GC machines.
'========================================================================== ' ' 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
Post #: 1
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
>> get AD roles
Page:
[1]
Jump to:
Select a Forum
All Forums
----------------------
[Welcome]
- - Forum Rules
- - Test Posting Messages
- - New Member Area/Introduction
[Scripting]
- - WSH & Client Side VBScript
- - WSH & Client Side VBScript Tutorial
- - Post a VBScript
- - Windows PowerShell
- - ASP
- - ASP.NET
- - Windows Script Components
[General Forum]
- - Other Programming/Scripting Languages
- - Suggestions & Feedback
- - Off-Topic Lounge
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
Forum Software ©
ASPPlayground.NET
Advanced Edition
2.5.5 ANSI