Kyle
Kyle

Reputation: 17677

ActiveDirectory Domain Description?

I'm trying to get some details about the current systems Domain. I've been able to find the Name, DomainMode and ForstMode by using the following code:

System.DirectoryServices.ActiveDirectory.Domain domain = System.DirectoryServices.ActiveDirectory.Domain.GetCurrentDomain();
Console.WriteLine("Domain: " + domain.Name);
Console.WriteLine("Domain Mode: " + domain.DomainMode);
Console.WriteLine("Forest Mode: " + domain.Forest.ForestMode);

However, I cannot seem to figure out how to get the domains description. Screenshot of what I am looking for:

Looking for

Any suggestions on how I can go about getting this? I don't see any attributes on the Domain object that seems to represent it.

Upvotes: 3

Views: 921

Answers (1)

Kyle
Kyle

Reputation: 17677

Figured it out. Along with the description I was also able to get the SID using the following code:

            using (System.DirectoryServices.ActiveDirectory.Domain domain = System.DirectoryServices.ActiveDirectory.Domain.GetCurrentDomain())
            {
                using (DirectoryEntry directoryEntry = domain.GetDirectoryEntry())
                {
                    Console.WriteLine("Domain: " + domain.Name);
                    Console.WriteLine("Domain Mode: " + domain.DomainMode);
                    Console.WriteLine("Forest Mode: " + domain.Forest.ForestMode);

                    var sidInBytes = directoryEntry.Properties["objectSID"].Value as byte[];
                    var sid = new SecurityIdentifier(sidInBytes, 0);
                    Console.WriteLine("Domain SID: " + sid.ToString());

                    Console.WriteLine("Description: " + directoryEntry.Properties["description"].Value as string);
                }
            }

Upvotes: 3

Related Questions