怎么获取AD组里的用户
1个回答
展开全部
手写不容易,请采纳。
public partial class adgroup : System.Web.UI.Page
{
string LDAP = "…………";
string groupName = "USB 15DRW";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
StringCollection groupMembers = this.GetGroupMembers(groupName);
foreach (var user in groupMembers)
{
Response.Write(user.ToString() + "<br/>");
}
}
}
public StringCollection GetGroupMembers(string strGroup)
{
StringCollection groupMemebers = new StringCollection();
try
{
DirectoryEntry ent = new DirectoryEntry(LDAP);
DirectorySearcher srch = new DirectorySearcher("(CN=" + strGroup + ")");
SearchResultCollection coll = srch.FindAll();
foreach (SearchResult rs in coll)
{
ResultPropertyCollection resultPropColl = rs.Properties;
foreach (Object memberColl in resultPropColl["member"])
{
DirectoryEntry gpMemberEntry = new DirectoryEntry("LDAP://" + memberColl);
System.DirectoryServices.PropertyCollection userProps = gpMemberEntry.Properties;
object obVal = userProps["sAMAccountName"].Value;
if (null != obVal)
{
groupMemebers.Add(obVal.ToString());
}
}
}
}
catch (Exception ex)
{
throw;
}
return groupMemebers;
}
}
public partial class adgroup : System.Web.UI.Page
{
string LDAP = "…………";
string groupName = "USB 15DRW";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
StringCollection groupMembers = this.GetGroupMembers(groupName);
foreach (var user in groupMembers)
{
Response.Write(user.ToString() + "<br/>");
}
}
}
public StringCollection GetGroupMembers(string strGroup)
{
StringCollection groupMemebers = new StringCollection();
try
{
DirectoryEntry ent = new DirectoryEntry(LDAP);
DirectorySearcher srch = new DirectorySearcher("(CN=" + strGroup + ")");
SearchResultCollection coll = srch.FindAll();
foreach (SearchResult rs in coll)
{
ResultPropertyCollection resultPropColl = rs.Properties;
foreach (Object memberColl in resultPropColl["member"])
{
DirectoryEntry gpMemberEntry = new DirectoryEntry("LDAP://" + memberColl);
System.DirectoryServices.PropertyCollection userProps = gpMemberEntry.Properties;
object obVal = userProps["sAMAccountName"].Value;
if (null != obVal)
{
groupMemebers.Add(obVal.ToString());
}
}
}
}
catch (Exception ex)
{
throw;
}
return groupMemebers;
}
}
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家可靠的代理服务提供商,提供原生IP(住宅原生IP)和高匿名代理服务。以下是关于StormProxies的原生IP服务的一些信息:1. 住宅原生IP:StormProxies提供的住宅原生IP是指从真实的家庭或企...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询