首页 > 解决方案 > 获取有关组描述的 Active Directory 组及其成员的列表

问题描述

我想根据组描述(文本)获取 Active Directory 组及其成员(用户)的列表。如果输出文件采用以下格式,那就太好了:

第 1 组
用户 1
用户 2
用户 3
第 2 组
用户 2
用户 3
第 3 组
用户 1
......

到目前为止,我得到了包含描述中文本的组列表。我无法获得这些团体的成员。

Get-Adgroup -Filter * - Properties Name, Description | Select Name, Description | Where-Object {$_.Description -eq "description-text"} 

我确实得到了组(名称)和描述列表,其中仅包含具有所需描述的组。我试图继续, | Get-AdGroupMember -Identity但没有成功。

标签: powershell

解决方案


尽可能靠近管道的左端进行过滤会更有效,即用于描述。尝试这样的事情:

# Gets all groups with the specific description
$Groups = Get-ADGroup -Filter "Description -like 'description-text'"
# Iterate through the list of groups
foreach ($Group in $Groups) {
    $Group.Name  # Outputs the group name
    $Users = $Group | Get-ADGroupMember  # Gets the list of users in that group
    $Users.Name  # Outputs all the users' names
}

推荐阅读