Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am using C# and trying to check if a group exists or not in active directory I am doing this

string cmd = "New-Object DirectoryServices.DirectoryEntry \"LDAP://cn=" + groupname + " " + LdapDef + ",dc=twu,dc=ca\" | Select-Object name";
string result = execute(cmd);
return true;

this used to work in the past but from a while now I get following error whenever above code is executed.

Server was unable to process request. ---> The following exception occurred while    retrieving member "name": "There is no such object on the server.

" ---> The following exception occurred while retrieving member "name": "There is no such object on the server.

" ---> There is no such object on the server.

I am not sure what is wrong here? what else could i use to get the groupname other than using "name"

Can someone help me this please?

share|improve this question

1 Answer 1

This is what I use to search our directory:

 DirectoryEntry objDE;
 objDE = new DirectoryEntry("LDAP://cn=computers,dc=lab,dc=test");
 static String[] strProperties = { "name" };

 DirectorySearcher dd = new DirectorySearcher(objDE, "(&(objectCategory=group)(objectClass=user)(cn=name))", strProperties, SearchScope.Subtree);

this is C#, I've never mixed C# and powershell but this should get point you in the right direction. don't forget

Using System.DirectoryServices

also.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa746475(v=vs.85).aspx

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.