使用PowerShell查询指定用户可访问的所有Outlook邮箱权限
查找指定用户可访问的所有邮箱
要从单个用户(比如Ann)出发,找出她能访问的所有邮箱,不用提前知道目标邮箱的话,你可以遍历所有邮箱,筛选出该用户拥有有效权限的条目——排除掉用户自己的权限记录就行。
具体命令
# 把这里替换成目标用户的UPN或用户名 $targetUser = "Ann@contoso.com" Get-Mailbox -ResultSize Unlimited | ForEach-Object { $mailbox = $_ Get-MailboxPermission -Identity $mailbox.Identity | Where-Object { $_.User -like "*$targetUser*" -and $_.IsInherited -eq $false -and $_.User -ne $mailbox.PrimarySmtpAddress } | Select-Object @{Name="邮箱";Expression={$mailbox.PrimarySmtpAddress}}, AccessRights, IsInherited }
命令细节说明
Get-Mailbox -ResultSize Unlimited:拉取组织内所有邮箱,不管数量多少都能覆盖- 遍历每个邮箱,查询对应的权限列表
- 筛选条件拆解:
- 匹配目标用户的权限条目
- 排除继承的权限(如果需要包含继承权限,直接删掉
$_.IsInherited -eq $false这部分) - 排除用户自身的邮箱权限记录(默认会显示用户对自己邮箱的权限,这部分不需要)
- 最终输出邮箱地址、具体权限类型,以及权限是否为继承而来
简化版(仅输出邮箱地址)
如果只需要拿到邮箱列表,用下面的简化命令就行:
$targetUser = "Ann@contoso.com" Get-Mailbox -ResultSize Unlimited | ForEach-Object { $mailbox = $_ if (Get-MailboxPermission -Identity $mailbox.Identity | Where-Object { $_.User -like "*$targetUser*" -and $_.IsInherited -eq $false -and $_.User -ne $mailbox.PrimarySmtpAddress }) { $mailbox.PrimarySmtpAddress } }
内容的提问来源于stack exchange,提问作者Tyler Laidler
相关产品推荐
相关产品推荐

