Reputation: 2188
I get a list of security groups a user belongs to as array of objects. I use DirectoryEntry to get active directory properties and one of the properties is "memberOf" (de.properties["memberOf"].value). The return values is an "array of objects". Each element of this array of objects look something like:
"CN=SITE_MAINTENANCE,OU=CMS,OU=SD,OU=ESM,OU=Engineering Systems,DC=usa,DC=abc,DC=domain,DC=com"
I can loop through the elements, cast each element as "string" and search this way. I just thought there might be an easier way that does not require looping. I need to be able to find the one(s) with OU=CMS in it.
Thanks.
Upvotes: 0
Views: 158
Reputation: 17614
You can use like follows
string listString="CN=SITE_MAINTENANCE,OU=CMS,OU=SD,OU=ESM,"+
"OU=Engineering Systems,DC=usa,DC=abc,DC=domain,DC=com"
Using linq:
listString.Split(',').Contains("OU=CMS")
W/o linq:
Array.IndexOf(listString.Split(','), "OU=CMS") >= 0
Upvotes: 0
Reputation: 8488
list.Where(a=>a.ToString().Contains("OU=CMS")).ToList();
Upvotes: 0
Reputation: 3330
Loop through the array and then use indexOf or Regexp search for the string "OU=CMS". If it exists in the string, then you've "found the one(s) with OU=CMS in it."
You can do anything like throwing the items into a new list or whatever you want.
Upvotes: 2