【问题标题】:AD Export of Groups / Members of Each group and Email Addresses组/每个组的成员和电子邮件地址的 AD 导出
【发布时间】:2018-01-19 12:45:07
【问题描述】:

我想问是否有人可以帮助我使用脚本来提取所有 AD 组及其成员和电子邮件地址。我正在运行下面的脚本,我在其中一个帖子中找到了它,该帖子提取了所有 AD 组及其成员,但我也不知道如何包含他们的电子邮件地址。非常感谢您的帮助。

$Groups = Get-ADGroup -Filter * -SearchBase 'OU,OU,OU,OU,OU,DC,DC,DC' #creates a variable with the name Groups and stores all the groups into it

$Results = foreach( $Group in $Groups ){ #looks for members in each group and stores them in Results

    Get-ADGroupMember -Identity $Group | foreach {

        [pscustomobject]@{

            GroupName = $Group.Name

            Name = $_.Name

            }

        }

    }

$Results| sort -Property GroupName | Export-Csv -Path c:\temp\groups.csv -NoTypeInformation #stores results in a csv

【问题讨论】:

  • 应该使用mail 属性将Email 字段添加到[pscustomobject]@{...} 哈希表中。
  • 感谢您尝试提供帮助,但这不起作用。看起来应该添加一个带有 -SearchBase 的新变量来过滤邮件地址属性并添加到循环中。尝试了一些东西,但不起作用

标签: powershell active-directory export-to-csv


【解决方案1】:

您需要在foreach 循环中捕获用户的电子邮件地址,并且您需要通过查找用户属性来执行此操作 - 组成员列表只有成员 DN 和名称。

Get-ADGroupMember -Identity $Group | foreach {
    $u = get-aduser $_ -properties mail  ##plus any other user properties you need
    [pscustomobject]@{
        GroupName = $Group.Name
        Name = $u.Name
        Email = $u.mail
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-28
    • 1970-01-01
    • 1970-01-01
    • 2021-06-05
    • 1970-01-01
    • 2019-01-03
    • 2016-03-01
    相关资源
    最近更新 更多