I try to run a Script that will give mal participants of a mail-distributiongroup and their mailaddresses. For the participants it works quite well, while for the owners it doesent work, because im only able to get tehir displayname as String. Is there a way to get the Mailaddress by the Name of an exchange user.
# Get all distribution groups
$groups = Get-DistributionGroup -ResultSize Unlimited
# Loop through each group
foreach ($group in $groups) {
# Get the group's name and email address
$groupName = $group.Name
$groupEmail = $group.PrimarySmtpAddress
# Get the list of owners
$owners = $group.ManagedBy
# Get the list of participants
$participants = Get-DistributionGroupMember $group | Select-Object -
ExpandProperty PrimarySmtpAddress
#do smth with it
}
The term $Managed by only gives me the displayname of the Owners as String. I already tried to access the mailaddress by iterating through the list of owners:
foreach ($owner in $owners) {
$ownerAddress = Get-Mailbox -Filter "displayName -eq '$owner'"
}
It returns nothing, as well with the -Anr Flag or -Credentails.
Hi MirrahOH you can get the info from manager whit this line
# Get the list of owners
$owners = $group.ManagedBy
#manager informations
Get-ADUser -Identity $owners.DistinguishedName -Properties mail
# Get the list of participants