我有一个从 Active Directory 获取信息的 powershell 函数。它将发送一封电子邮件,电子邮件的正文将包含与该电子邮件地址关联的任何组。正如您在下面看到的,test@email.com 被列出了两次。与其向 test@email.com 发送 2 封电子邮件,我更愿意在正文中发送一封包含两个组的电子邮件。我怎样才能做到这一点?谢谢
email group
test@email.com number1
test@email.com number2
notet@email.com number1
hello@email.com number3
(Get-ADUser -Identity lbono –Properties MemberOf | Select MemberOf).MemberOf | Get-ADGroup -Properties ManagedBy | Select Name, ManagedBy, Distinguishedname, GroupCategory |
Where-Object {
$_.Distinguishedname -notlike "*Unity*" -and $_.Distinguishedname -notlike "*DynastyGroups*" -and $_.name -notlike "*Technical Library*" }|
ForEach-Object {
If ($_.ManagedBy) {
$result = New-Object PSObject
Add-Member -input $result NoteProperty 'Group Name' $_.Name
Add-Member -input $result NoteProperty 'Managed By' ((Get-ADUser -Identity $_.ManagedBy).givenName + ' ' + ((Get-ADUser -Identity $_.ManagedBy).surName))
Add-Member -input $result NoteProperty 'Email' (Get-ADUser -Identity $_.ManagedBy -Properties mail).Mail
Add-Member -input $result NoteProperty 'Group Type' $_.GroupCategory
Write-Output $result
}
} | select 'Group Name','Managed By','Email','Group Type' | sort 'Managed By'