如何查詢 Windows Active Directory Groups 成員

如何查詢 Windows Active Directory Groups 成員

如何查詢 Windows Active Directory Groups 成員

2020-12-10

筆記查詢 Windows AD Groups Members 的各種方式。

說明

使用網路 / 搜尋 Active Directory

原生於 Windows 10 作業系統之中,缺點是查詢的控制項目有限。

Sysinternals AD Explorer

Sysinternals 中輕量的工具,易於從 AD 中進行各種面向的查詢。

AD Explorer

.NET Framework

使用 System.DirectoryServices 向 LDAP Service 來做查詢。

using System.DirectoryServices;

public class ADUserQuery

{

public string Description { get; set; }

public string Name { get; set; }

public DateTime BadWordTimestamp{ get; set; }

public DateTime LastLogonTimestamp{ get; set; }

public string Result { get; set; }

}

public static ADUserQuery GetEmpAdgroup(string empId)

{

var adgroup = new ADUserQuery();

adgroup.Result = "";

Dictionary result = new Dictionary { };

if (empId != null && empId != "" && empId.Length <= 6)

{

DirectoryEntry entry = new DirectoryEntry("LDAP://domain.com.tw");

DirectorySearcher Dsearch = new DirectorySearcher(entry);

Dsearch.Filter = "(&(objectClass=user)(objectClass=person)(sAMAccountName=" + empId + "))";

foreach (SearchResult sResultSet in Dsearch.FindAll())

{

if (sResultSet.Properties["memberOf"].Count > 0)

{

var rs = "";

foreach (var s in sResultSet.Properties["memberOf"])

{

rs += s.ToString().Split(',')[0] + "
";

}

adgroup.Result = rs;

}

adgroup.Description = (string)sResultSet.Properties["description"][0];

adgroup.Name = (string)sResultSet.Properties["displayName"][0];

}

}

return adgroup;

}

PowerShell

藉由安裝 RAST 以取得使用 Powershell Active Directory Modules 的能力。

適用於 Windows 10 的遠端伺服器管理工具

MSDN - Powershell, ActiveDirectory

參考資料

安裝POWERSHELL - ACTIVE DIRECTORY MODULE解決AD大小事

相关推荐

工坊(辐射4)
365体育投注备用网站

工坊(辐射4)

📅 08-10 👁️ 5541
centos下php如何升级
365bet提款时间

centos下php如何升级

📅 07-13 👁️ 185
泰拉瑞亚迷你鲨有必要买吗?(泰拉瑞亚1.4迷你鲨最高属性)
365体育投注备用网站

泰拉瑞亚迷你鲨有必要买吗?(泰拉瑞亚1.4迷你鲨最高属性)

📅 07-28 👁️ 7116