How to Find the FSMO Role Owners Using ADSI and WSH

This article has been archived. It is offered "as is" and will no longer be updated.
Summary
This article contains a sample script that outputs the Flexible Single Master of Operations (FSMO) role owners for a specified domain or domain controller.
More information
To use the script, cut and paste the code into a text file and then save the file as Find_fsmo.vbs.

The following script is in Microsoft Visual Basic Scripting language.
Option ExplicitDim WSHNetwork, objArgs, ADOconnObj, bstrADOQueryString, RootDom, RSObjDim FSMOobj,CompNTDS, Computer, Path, HelpTextSet WSHNetwork = CreateObject("WScript.Network")Set objArgs = WScript.ArgumentsHelpText = "This script will find the FSMO role owners for your domain." & Chr(13) &_           Chr(10) & "The syntax is as follows:" & Chr(13) & Chr(10) &_           "find_fsmo DC=MYDOM,DC=COM" & Chr(13) & Chr(10) &_           """Where MYDOM.COM is your domain name.""" & Chr(13) & Chr(10) & "OR:" &_           Chr(13) & Chr(10) & "find_fsmo MYDCNAME " & Chr(13) & Chr(10) &_           """Where MYDCNAME is the name of a Windows 2000 Domain Controller"""Select Case objArgs.Count    Case 0        Path = InputBox("Enter your DC name or the DN for your domain"&_                        " 'DC=MYDOM,DC=COM':","Enter path",WSHNetwork.ComputerName)    Case 1        Select Case UCase(objArgs(0))            Case "?"                WScript.Echo HelpText                WScript.Quit            Case "/?"                WScript.Echo HelpText                WScript.Quit            Case "HELP"                WScript.Echo HelpText                WScript.Quit            Case Else                Path = objArgs(0)        End Select    Case Else        WScript.Echo HelpText        WScript.QuitEnd SelectSet ADOconnObj = CreateObject("ADODB.Connection")ADOconnObj.Provider = "ADSDSOObject"ADOconnObj.Open "ADs Provider"'PDC FSMObstrADOQueryString = "<LDAP://"&Path&">;(&(objectClass=domainDNS)(fSMORoleOwner=*));adspath;subtree"Set RootDom = GetObject("LDAP://RootDSE")Set RSObj = ADOconnObj.Execute(bstrADOQueryString)Set FSMOobj = GetObject(RSObj.Fields(0).Value)Set CompNTDS = GetObject("LDAP://" & FSMOobj.fSMORoleOwner)Set Computer = GetObject(CompNTDS.Parent)WScript.Echo "The PDC FSMO is: " & Computer.dnsHostName'Rid FSMObstrADOQueryString = "<LDAP://"&Path&">;(&(objectClass=rIDManager)(fSMORoleOwner=*));adspath;subtree"Set RSObj = ADOconnObj.Execute(bstrADOQueryString)Set FSMOobj = GetObject(RSObj.Fields(0).Value)Set CompNTDS = GetObject("LDAP://" & FSMOobj.fSMORoleOwner)Set Computer = GetObject(CompNTDS.Parent)WScript.Echo "The RID FSMO is: " & Computer.dnsHostName'Infrastructure FSMObstrADOQueryString = "<LDAP://"&Path&">;(&(objectClass=infrastructureUpdate)(fSMORoleOwner=*));adspath;subtree"Set RSObj = ADOconnObj.Execute(bstrADOQueryString)Set FSMOobj = GetObject(RSObj.Fields(0).Value)Set CompNTDS = GetObject("LDAP://" & FSMOobj.fSMORoleOwner)Set Computer = GetObject(CompNTDS.Parent)WScript.Echo "The Infrastructure FSMO is: " & Computer.dnsHostName'Schema FSMObstrADOQueryString = "<LDAP://"&RootDom.Get("schemaNamingContext")&_                     ">;(&(objectClass=dMD)(fSMORoleOwner=*));adspath;subtree"Set RSObj = ADOconnObj.Execute(bstrADOQueryString)Set FSMOobj = GetObject(RSObj.Fields(0).Value)Set CompNTDS = GetObject("LDAP://" & FSMOobj.fSMORoleOwner)Set Computer = GetObject(CompNTDS.Parent)WScript.Echo "The Schema FSMO is: " & Computer.dnsHostName'Domain Naming FSMObstrADOQueryString = "<LDAP://"&RootDom.Get("configurationNamingContext")&_                     ">;(&(objectClass=crossRefContainer)(fSMORoleOwner=*));adspath;subtree"Set RSObj = ADOconnObj.Execute(bstrADOQueryString)Set FSMOobj = GetObject(RSObj.Fields(0).Value)Set CompNTDS = GetObject("LDAP://" & FSMOobj.fSMORoleOwner)Set Computer = GetObject(CompNTDS.Parent)WScript.Echo "The Domain Naming FSMO is: " & Computer.dnsHostName				
For more information about Active Directory Services Interface (ADSI), refer to the following Microsoft Web site: For more information about Windows Script Host, refer to the following Microsoft Web site: For additional informationFSMO roles in Windows 2000, click the article number below to view the article in the Microsoft Knowledge Base:
197132 Windows 2000 Active Directory FSMO Roles
Properties

Article ID: 235617 - Last Review: 12/05/2015 15:01:43 - Revision: 3.0

Microsoft Windows 2000 Server

  • kbnosurvey kbarchive kbhowto KB235617
Feedback