【问题标题】:PowerShell to list Exchange mailbox that have Full Access delegate permission more than 1 personPowerShell 列出具有超过 1 人的完全访问委托权限的 Exchange 邮箱
【发布时间】:2019-02-08 11:53:06
【问题描述】:

我需要知道哪个 Exchange 用户邮箱当前被不止一个人访问,而不是用户显示名本身。这是我的代码:

Get-Mailbox -ResultSize Unlimited | Get-MailboxPermission | Where-Object { ($_.AccessRights -eq "FullAccess") -and ($_.IsInherited -eq $false) -and -not ($_.User -like "NT AUTHORITY\SELF") -and -not ($_.User -like '*Discovery Management*') } |
   Select @{Name="User Name";expression={(Get-Recipient $_.user.tostring()).displayname}}, Identity,AccessRights,PrimarySMTPAddress | Export-Csv C:\Results.csv -NoTypeInformation

这里需要解决什么问题?

【问题讨论】:

  • "or fix the above",代码有什么问题?

标签: powershell active-directory office365 exchange-server


【解决方案1】:

虽然使用-and -not 是正确的,但我不会说这不是最优雅的方法,因为-like-eq 存在相反的运算符(@Paxz 在现已删除的 cmets 中建议)。您的 where 声明可以修改为:

 Where-Object { ($_.AccessRights -like "*FullAccess*") -and (-not $_.IsInherited) -and ($_.User -ne "NT AUTHORITY\SELF") -and ($_.User -notlike '*Discovery Management*') }

我所做的更改:

# from
($_.AccessRights -eq "FullAccess")
# to 
($_.AccessRights -like "*FullAccess*")

包括当用户在AccessRight 中拥有一个或多个访问条目的情况(尽管我不确定它在现实生活中是否需要)。您的代码将过滤 {FullAccess, ReadPermission},因为它不等于 FullAccess

# from
($_.IsInherited -eq $false) 
# to 
(-not $_.IsInherited)

为什么?更优雅。 IsInherited 是布尔值,可以直接使用-not

# from
-and -not ($_.User -like "NT AUTHORITY\SELF")
# to
-and ($_.User -ne "NT AUTHORITY\SELF")

为什么? like/notlike这里不需要,可以直接使用-ne

# from 
-and -not ($_.User -like '*Discovery Management*')
# to
-and ($_.User -notlike '*Discovery Management*')

与上面类似,但我不确定这里可能有哪些值,所以我没有更改为 -ne


另外,在您的Select-Object 中,您使用PrimarySMTPAddress,因为权限条目没有这样的参数,所以它不起作用。您必须使用与 User Name 类似的方法(另外,我认为在这种情况下不需要 .ToString()):

@{Name="PrimarySMTPAddress";expression={(Get-Recipient $_.user).PrimarySMTPAddress}}

【讨论】:

  • 酷,非常感谢 Robby 的分享和解释,非常感谢。
【解决方案2】:

您可以尝试以下代码列出具有完全访问委托权限的 Exchange 邮箱:

Get-Mailbox -ResultSize Unlimited | Get-MailboxPermission | Where-Object { ($_.AccessRights -like "*FullAccess*") -and (-not $_.IsInherited) -and ($_.User -ne "NT AUTHORITY\SELF") -and ($_.User -notlike '*Discovery Management*') } |
Select @{Name="User Name";expression={(Get-Recipient $_.user.tostring()).displayname}}, Identity,AccessRights,PrimarySMTPAddress | Export-Csv C:\Results.csv -NoTypeInformation

【讨论】:

  • 感谢 Yuki 在这件事上的帮助。
猜你喜欢
  • 2011-01-01
  • 2014-12-13
  • 2013-05-18
  • 1970-01-01
  • 2010-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-07
相关资源
最近更新 更多