powershell 如何通过Exchange用户名获取邮件地址

jk9hmnmh  于 2023-04-12  发布在  Shell
关注(0)|答案(1)|浏览(124)

我试着运行一个脚本,它会给予一个邮件分发组的mal参与者和他们的mailaddresses.对于参与者来说,它工作得很好,而对于所有者来说,它不工作,因为我只能得到字符串的显示名称.有没有一种方法可以通过交换用户的名称来获得Mailaddress.

# 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
}

术语$Managed by只给出了Owners的字符串形式的显示名称。我已经尝试通过遍历所有者列表来访问邮件地址:

foreach ($owner in $owners) {
$ownerAddress = Get-Mailbox -Filter "displayName -eq '$owner'"
}

它不返回任何内容,也不返回-Anr Flag或-Credentails。

y53ybaqx

y53ybaqx1#

Hi MirrahOH,您可以通过这条线从经理那里获得信息

# Get the list of owners
$owners = $group.ManagedBy 
    #manager informations 
    Get-ADUser -Identity $owners.DistinguishedName -Properties mail
# Get the list of participants

相关问题