Posts
23
Comments
229
Trackbacks
0
June 2007 Blog Posts
Finding FSMO's Fast

OK folks, here's a little ditty for you all,

 

I was looking for the fastest way to find, or actually remember, which servers on our network held which FSMO roles. I knew which ones they were, I just didn't know which server held which role.

 

What I mean is, I know which two servers had FSMO roles, I just didn't know which roles were on which server. Actually,we have something like 40 Domain controllers. OK, instead of guessing, let me check how many domain controllers we have. Here is a script I use just for that purpose:

'Begin Script

On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
"SELECT ADsPath FROM 'LDAP://" & strConfigurationNC & "' WHERE objectClass='nTDSDSA'"
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Set objParent = GetObject(GetObject(objRecordset.Fields("ADsPath")).Parent)
WScript.Echo objParent.CN '& " " & objparent.adsPath
varcount = varcount + 1
objRecordSet.MoveNext
Loop

wscript.echo varCount

'End Script

 

Go ahead and copy and past that into notepad and save it as a .vbs file. Name it something like getAllDomainControllers.vbs. Run it from the command prompt like this: cscript getalldomaincontrollers.vbs.

Or, better yet, run the folllowing command to make cscript your default scripting host: cscript //h:cscript

If you want to switch back to wscript (so that you get popups for the output instead of having the output of a .vbs file go to the command line) then do this:

cscript //h:wscript

you could also do wscript //h:cscript or wscript //h:wscript to get the same thing. The difference? When you run wscript, the confirmation is returned in a popup window, when you run cscript the confirmation is returned on the command line. I just remember it as the "c" in cscript is for command line, and the "w" in wscript is for windows.

 

So, I have more than 40. I'm not telling you exaclty how many, but I have a lot.

 

So anyway, to find your FSMO roles really quick just run the following: netdom query fsmo

That's it! You get a nice output of your FSMO roles, one per line, and which server is the owner of that role. To get the netdom tool simply install "The Windows Server 2003 Administration Tools Pack" onto your local machine. Windows Server 2003 has the netdom tool by default, but not Windows XP. I'm not sure about Vista (yuk.)

posted @ Thursday, June 28, 2007 10:46 AM | Feedback (9)