Skip navigation

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

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 Explicit
Dim WSHNetwork, objArgs, ADOconnObj, bstrADOQueryString, RootDom, RSObj
Dim FSMOobj,CompNTDS, Computer, Path, HelpText, LocalDNSName, strComputerDN, objSysInfo, objComputer

Set WSHNetwork = CreateObject("WScript.Network")
Path = WSHNetwork.ComputerName

Set objSysInfo = CreateObject("ADSystemInfo")
strComputerDN = objSysInfo.ComputerName

Set objComputer = GetObject("LDAP://" & strComputerDN)
LocalDNSName = objComputer.dNSHostName

Set ADOconnObj = CreateObject("ADODB.Connection")

ADOconnObj.Provider = "ADSDSOObject"
ADOconnObj.Open "ADs Provider"

'PDC FSMO
bstrADOQueryString = "<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)
if StrComp(LocalDNSName, Computer.dnsHostName) = 0 then
WScript.Echo "PDC"
end if

'Rid FSMO
bstrADOQueryString = "<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)
if StrComp(LocalDNSName, Computer.dnsHostName) = 0 then
WScript.Echo "RIS"
end if

'Infrastructure FSMO
bstrADOQueryString = "<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)
if StrComp(LocalDNSName, Computer.dnsHostName) = 0 then
WScript.Echo "Infrastructure"
end if

'Schema FSMO
bstrADOQueryString = "<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)
if StrComp(LocalDNSName, Computer.dnsHostName) = 0 then
WScript.Echo "Schema"
end if

'Domain Naming FSMO
bstrADOQueryString = "<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)
if StrComp(LocalDNSName, Computer.dnsHostName) = 0 then
WScript.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:

PDC
RIS
Infrastructure
Schema
Domain 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).

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish