【发布时间】: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