How to get the Email Addresses of the owners of an Exchange Distribution Group?
Following PS cmdlet can be used to extract the Email Addresses of the owners of an Exchange Distribution Group
$Admins=(Get-DistributionGroup -Identity “theoffice” | Select-object -ExpandProperty ManagedBy)
$results = foreach ($Admin in $Admins)
{$mailbox=(Get-Mailbox -Identity $Admin).PrimarySmtpAddress
$mailbox>>C:\Report\Report.csv
}
I love it – simple and elegant!
I had to add one small detail to get the output I was after though – if concatenating to a string instead of file, I had to use .ToString() to get it to behave properly.
In this case I am querying the Distribution Group to find the Managers and then pass a ad/remove request directly to them instead of IT having to do the footwork…
$Mailboxes += $Mailbox.ToString() + “; ” allows me to use $Mailboxes to populate the To: field
Again – simple and elegant – thank you much for posting it.
Thank you very much for the comments
It does not work
what is the issue?
Sorry for the late response.
When the script gets to the (Get-Mailbox -Identity $Admin) it throws an error:
The operation couldn’t be performed because object ‘corp.contoso.com/Users/Canon, Frank’ couldn’t be found on ‘DC2.corp.contoso.com’.
All the groups have owners and it happens on all owners.
Users are in EXO and the DG’s are in EX on prem.
Please advise.