当我使用下面的代码获取组列表时,我得到一个代表组名的长字符串
CN=group.xy.admin.si,OU=Other,OU=Groups,OU=03,OU=UWP 客户,DC=WIN,DC=CORP,DC=com
但我只想获取在本例中为group.xy.admin.si的组名
public static List<string> GetGroups(DirectoryEntry de)
{
var memberGroups = de.Properties["memberOf"].Value;
var groups = new List<string>();
if (memberGroups != null)
{
if (memberGroups is string)
{
groups.Add((String)memberGroups);
}
else if (memberGroups.GetType().IsArray)
{
var memberGroupsEnumerable = memberGroups as IEnumerable;
if (memberGroupsEnumerable != null)
{
foreach (var groupname in memberGroupsEnumerable)
{
groups.Add(groupname.ToString());
}
}
}
}
return groups;
}