-1

The following code in Powershell gets me the ntdsaGUID of a DC (for use in repadmin)

Get-ADDomainController -filter * | Select-Object -Property Name, IPv4Address, @{n='DsaGuid'; e={(Get-ADObject $_.NTDSSettingsObjectDN).ObjectGUID}}

I am having a hard time generating equivalent in C#.

There is a private member on DomainController (derived from: domain.DomainControllers) called NtdsaObjectGuid but I don't know if I can get to that, even though VS can.

Is there a supported way to get the DSA GUID of a DC in C#?

Thanks!

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
dragonspeed
  • 255
  • 2
  • 13
  • 1
    I don't understand your question. How do you want to fetch this data with C#? Do you want to reference System.Management.Automation and run your PS one-liner? Or do you want to use the System.DirectoryServices namespace? Note that using the FindAll() method for the System.DirectoryServices.ActiveDirectory.DomainController class should give you most of the information (or just do a lookup on the directoryEntry of the specific Domain Controller and retrieve the required property). – bluuf May 08 '18 at 07:59
  • I want to do this in C#. I can get all the DC's no problem. I just can't get to the DSA GUID of it in C# that I can see. When I have a DC and inspect it in VS, I can see Non-Public members has "NtdsaObjectGuid" That's what I want to get to, but as it appears to be non-public, I don't know how.... – dragonspeed May 08 '18 at 14:37

1 Answers1

0

I ended up using a helper class as provided by Steinberg in this answer: I need to access a non-public member (Highlighted Item) of a Combo Box

This allowed me to get my NtdsaObjectGuid that I needed.

dragonspeed
  • 255
  • 2
  • 13