views:

66

answers:

1

I need to identify the schema master for a forest using C#. I know there are some available namespaces using System.DirectoryServices and System.DirectoryServices.ActiveDirectory but I can't seem to find any sample code that can return this information.

I suppose I could trudge through the configuration partition but I would think there is a namespace that could be used to go directly to the source...

A: 

I was able to get this syntax to work but wonder if it's not the best way to handle this...

DirectoryContext dirContext = new DirectoryContext(DirectoryContextType.DirectoryServer,"domain.com", "Username", "Password");
Forest forest = Forest.GetForest(dirContext);
string schemaMaster = forest.SchemaRoleOwner.Name;

or using integrated credentials:

Forest forest = Forest.GetCurrentForest();
string schemaMaster = forest.SchemaRoleOwner.Name;
Dscoduc