组/每个组的成员和电子邮件地址的 AD 导出
AD Export of Groups / Members of Each group and Email Addresses
我想问问有没有人能帮我写一个脚本来提取所有 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
您需要在 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
}
}
我想问问有没有人能帮我写一个脚本来提取所有 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
您需要在 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
}
}