Reputation: 557
I am trying to collect all the server objects in a OU in AD with C#, but I am not successful.
I try to access the OU like this:
var context = new PrincipalContext(ContextType.Domain, "NO", "OU=Servers");
Is this correct?
And I try to group with this:
var groupPrincipal = new GroupPrincipal(context, "*");
But that throws an error.
What is the right way to go about to access the objects in a OU?
Upvotes: 1
Views: 844
Reputation: 557
I found the problem. The Servers OU did not have any groups inside it. Only more OU's based on Windows Server version. So to access the servers inside the OU's I had to reference nested OU like this: OU=2012, OU=Servers.
I also had to drop GroupPrincipal.
To access the servers I used the code from "Enumerate Objects in a OU" at http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C#19
Upvotes: 1