Skip to content

Instantly share code, notes, and snippets.

@JPBlanc
Created July 14, 2011 10:13
Show Gist options
  • Save JPBlanc/1082221 to your computer and use it in GitHub Desktop.
Save JPBlanc/1082221 to your computer and use it in GitHub Desktop.
Retreive the FSMO roles from a Domain Controler usind ADSI
'==========================================================================
'
' NAME: fSMORoleOwner.vbs
'
' AUTHOR: JPB , Silogix
' DATE : 13/07/2011
'
' COMMENT: This script allow to retreive the five FSMO Role Owners
'
'==========================================================================
Option Explicit
Dim machine ' A domain controler adress
Dim oRootDSE ' Root Directory Service Specific Entry
Dim DomainContainer ' The domain Root
Dim SchemaContainer ' The Schema Root
Dim ConfigurationContainer ' The Configuration Root
Dim conn ' ADODB connexion
Dim ldapBase ' Search base
Dim ldapFilter ' Search filter
Dim ldapAttributes ' Attributs to get
Dim ldapScope ' Search scope
Dim ldapStr ' String to execute
Dim rs ' Search result
Dim f '
Dim oADSI ' Acces to ADSI
Dim oFound ' Object found
Dim iCpt ' Counter
' Cuisine ADODB
machine = "192.168.183.138"
Set oRootDSE = GetObject("LDAP://"&machine&"/"&"RootDSE")
DomainContainer = oRootDSE.Get("defaultNamingContext")
SchemaContainer = oRootDSE.Get("schemaNamingContext")
ConfigurationContainer = oRootDSE.Get("configurationNamingContext")
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADSDSOObject"
conn.Properties("User ID") = "societe\administrateur"
conn.Properties("Password") = "test.2011"
conn.Properties("Encrypt Password") = True
conn.Open "ADs Provider"
' Buid the query to seach the 3 domain FSMOs
ldapBase = "<LDAP://" & machine &"/"& DomainContainer & ">"
ldapFilter = "(fsmoRoleOwner=*)"
ldapAttributes = "fsmoRoleOwner,distinguishedName"
ldapScope = "subtree"
ldapStr = ldapBase&";"&ldapFilter&";"&ldapAttributes&";"&ldapScope
' Query execution
Set rs = conn.Execute(ldapStr)
' Show the result
iCpt = 0
While Not rs.EOF
iCpt = iCpt+1
WScript.Echo "Role " & iCpt
For each f in rs.Fields
WScript.Echo f.name & ":" & f.Value
Next
rs.MoveNext
Wend
' Buid the query to seach the Schema FSMOs
ldapBase = "<LDAP://" & machine &"/"& SchemaContainer & ">"
ldapFilter = "(fsmoRoleOwner=*)"
ldapAttributes = "fsmoRoleOwner,distinguishedName"
ldapScope = "subtree"
ldapStr = ldapBase&";"&ldapFilter&";"&ldapAttributes&";"&ldapScope
' Query execution
Set rs = conn.Execute(ldapStr)
' Show the result
While Not rs.EOF
WScript.Echo "Schema Role "
For each f in rs.Fields
WScript.Echo f.name & ":" & f.Value
Next
rs.MoveNext
Wend
' Buid the query to seach the domain master FSMOs
ldapBase = "<LDAP://" & machine &"/"& ConfigurationContainer & ">"
ldapFilter = "(fsmoRoleOwner=*)"
ldapAttributes = "fsmoRoleOwner,distinguishedName"
ldapScope = "subtree"
ldapStr = ldapBase&";"&ldapFilter&";"&ldapAttributes&";"&ldapScope
' Query execution
Set rs = conn.Execute(ldapStr)
' Show the result
While Not rs.EOF
WScript.Echo "Domain master Role "
For each f in rs.Fields
WScript.Echo f.name & ":" & f.Value
Next
rs.MoveNext
Wend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment