How can I check the Flexible Single-Master Operation (FSMO) roles for the local server from the command line?

John Savill

March 29, 2004

1 Min Read
ITPro Today logo in a gray background | ITPro Today

A. I've written a short VBScript script called localsrvroles.vbs that displays on screen the FSMO roles that the current server holds. (My script is based on a script that Microsoft created to list all the roles of a forest; I've changed the Microsoft script to compare these roles to the local server's roles and display only the roles that match.) Localsrvroles.vbs, which is available at the Windows & .NET Magazine Web site, is listed below.

Option ExplicitDim WSHNetwork, objArgs, ADOconnObj, bstrADOQueryString, RootDom, RSObjDim FSMOobj,CompNTDS, Computer, Path, HelpText, LocalDNSName, strComputerDN, objSysInfo, objComputerSet WSHNetwork = CreateObject("WScript.Network")Path = WSHNetwork.ComputerNameSet objSysInfo = CreateObject("ADSystemInfo")strComputerDN = objSysInfo.ComputerNameSet objComputer = GetObject("LDAP://" & strComputerDN)LocalDNSName = objComputer.dNSHostNameSet ADOconnObj = CreateObject("ADODB.Connection")ADOconnObj.Provider = "ADSDSOObject"ADOconnObj.Open "ADs Provider"'PDC FSMObstrADOQueryString = ";(&(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)if StrComp(LocalDNSName, Computer.dnsHostName) = 0 thenWScript.Echo "PDC"end if'Rid FSMObstrADOQueryString = ";(&(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)if StrComp(LocalDNSName, Computer.dnsHostName) = 0 thenWScript.Echo "RIS"end if'Infrastructure FSMObstrADOQueryString = ";(&(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)if StrComp(LocalDNSName, Computer.dnsHostName) = 0 thenWScript.Echo "Infrastructure"end if'Schema FSMObstrADOQueryString = ";(&(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)if StrComp(LocalDNSName, Computer.dnsHostName) = 0 thenWScript.Echo "Schema"end if'Domain Naming FSMObstrADOQueryString = ";(&(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)if StrComp(LocalDNSName, Computer.dnsHostName) = 0 thenWScript.Echo "Domain Naming"end if

To execute the script, at the command prompt type

cscript //nologo localsrvroles.vbs

The script output will look similar to the following:

PDCRISInfrastructureSchemaDomain Naming

Notice that the script doesn't output anything except the roles that the machine holds (in this case, the server holds all five FSMO roles).

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like