I have a powershell function that gets information from Active directory. It will send an email and the body of the email will contain whatever group is associated with that email address. As you can see below [email protected] is listed twice. Rather sending 2 emails to [email protected], I would rather send one e-mail with both groups in the body. How can I achieve this? Thanks
email group
[email protected] number1
[email protected] number2
[email protected] number1
[email protected] 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'