Get FSMO Roles ?

J

JerryP

Hi Group,

is there any way to get the FSMO Roles using the Framework (C# prefered).

I would like to know what fsmo roles the current computer my software is
running on has.

Thanks !

Jerry
 
R

Ross Donald

Hi,

You have two options.

The first is the System.DirectoryServices namespace which is probably the
best option as it is managed. You need to add a reference to
System.DirectoryServices before you can use it. From there write some code
like:

// C#
using System.DirectoryServices;
// ...
DirectoryEntry RootDSE = new DirectoryEntry("LDAP://rootDSE");

The other option is to use COM Interop and add a reference to the Active DS
Type Library. Your code would look something like this (and the vbscript
below would be easier to convert)

using ActiveDs;
// ...
IADsContainer RootContainer =
(IADsContainer)Microsoft.VisualBasic.Interaction.GetObject("LDAP://rootDSE",
null);

Note that I could not find a suitable method in C# to replace GetObject so
you will need a reference to the Microsoft.VisualBasic library. If anyone
knows the way to "GetObject" in C# I would like to know!

--
Ross Donald
Rad Software
http://www.radsoftware.com.au

' Here is a VBScript that lists FSMO roles that you can convert to C#

Set objRootDSE = GetObject("LDAP://rootDSE")

' Schema Master
Set objSchema = GetObject("LDAP://" & objRootDSE.Get("schemaNamingContext"))
strSchemaMaster = objSchema.Get("fSMORoleOwner")
Set objNtds = GetObject("LDAP://" & strSchemaMaster)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo "Forest-wide Schema Master FSMO: " & objComputer.Name

Set objNtds = Nothing
Set objComputer = Nothing

' Domain Naming Master
Set objPartitions = GetObject("LDAP://CN=Partitions," & _
objRootDSE.Get("configurationNamingContext"))
strDomainNamingMaster = objPartitions.Get("fSMORoleOwner")
Set objNtds = GetObject("LDAP://" & strDomainNamingMaster)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo "Forest-wide Domain Naming Master FSMO: " & objComputer.Name

Set objNtds = Nothing
Set objComputer = Nothing

' PDC Emulator
Set objDomain = GetObject("LDAP://" &
objRootDSE.Get("defaultNamingContext"))
strPdcEmulator = objDomain.Get("fSMORoleOwner")
Set objNtds = GetObject("LDAP://" & strPdcEmulator)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo "Domain's PDC Emulator FSMO: " & objComputer.Name

Set objNtds = Nothing
Set objComputer = Nothing

' RID Master
Set objRidManager = GetObject("LDAP://CN=RID Manager$,CN=System," & _
objRootDSE.Get("defaultNamingContext"))
strRidMaster = objRidManager.Get("fSMORoleOwner")
Set objNtds = GetObject("LDAP://" & strRidMaster)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo "Domain's RID Master FSMO: " & objComputer.Name

Set objNtds = Nothing
Set objComputer = Nothing

' Infrastructure Master
Set objInfrastructure = GetObject("LDAP://CN=Infrastructure," & _
objRootDSE.Get("defaultNamingContext"))
strInfrastructureMaster = objInfrastructure.Get("fSMORoleOwner")
Set objNtds = GetObject("LDAP://" & strInfrastructureMaster)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo "Domain's Infrastructure Master FSMO: " & objComputer.Name



| Hi Group,
|
| is there any way to get the FSMO Roles using the Framework (C# prefered).
|
| I would like to know what fsmo roles the current computer my software is
| running on has.
|
| Thanks !
|
| Jerry
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top