Powershell - Exchange - 删除几乎所有邮箱权限

时间:2015-06-22 12:39:26

标签: powershell exchange-server rights

我原来的问题有点复杂。然而,一些很酷的成员确实设法帮助了我。

我从Vesper那里得到了以下代码:

$mailbox=get-mailbox $username
$perms=get-mailboxpermission $mailbox | where {$_.isinherited -eq $false -and $_.user.toString() -ne "NT AUTHORITY\SELF"}
$perms | remove-mailboxpermission $mailbox -confirm:$false

当我在Exchange PowerShell中逐个运行这些命令时,它可以很好地工作。但是,当我尝试使用该片段运行我的完整脚本时,我收到以下错误:

Cannot process argument transformation on parameter 'Identity'. Cannot convert the "USERNAME" value of type
"Deserialized.Microsoft.Exchange.Data.Directory.Management.Mailbox" to type
"Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter".
    + CategoryInfo          : InvalidData: (:) [Get-MailboxPermission], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-MailboxPermission
    + PSComputerName        : SERVER

知道如何解决这个问题吗?

3 个答案:

答案 0 :(得分:0)

快速而肮脏的解决方案可以是这样的:

$mailbox=get-mailbox $user #populate this first
$perms=get-mailboxpermissions $mailbox | where {$_.isinherited -eq $false -and $_.user.toString() -ne "NT AUTHORITY\SELF"}
$perms | remove-mailboxpermission $mailbox -whatif

请注意,此脚本的错误用户可能会破坏您的Exchange组织,可能会在单个邮箱上对其进行测试。该脚本未经过测试,但符合Exchange和Powershell上的手册。

说明:第一行获取有问题的邮箱。第二行首先在Exchange邮箱对象上获取完整ACL,然后仅过滤那些未继承的$_.IsInherited -eq $false条目,并过滤掉NT AUTHORITY\SELF,这需要出现在某人之前访问邮箱 - 此条目不会被继承。其他所有内容都被视为您希望删除的权限(此类权限直接添加到邮箱中,因此不会继承)。第三行删除通过对管道调用Remove-MailboxPermission确定的权限。请注意-whatif开关,它使cmdlet显示在将脚本启动到生产环境之前要由管理员审核的内容。

答案 1 :(得分:0)

约翰,

我遇到了同样的问题。

我做了一个改变,它把问题推倒了但没有解决它。

$Mailboxes = Get-Mailbox testmailbox

foreach($Mailbox in $Mailboxes)    {
$FixAutoMappings = Get-MailboxPermission $Mailbox.DisplayName |where {$_.AccessRights -eq "FullAccess" -and $_.IsInherited -eq $false}
    Foreach($FixAutoMapping in $FixAutoMappings){
    $FixAutoMapping | Remove-MailboxPermission $Mailbox.DisplayName
    $FixAutoMapping | Add-MailboxPermission -Identity $_.Identity -User $_.User -AccessRights:FullAccess -AutoMapping $false
    }
}

我只是在$ Mailbox之后添加了 .DisplayName ,这解决了获取权限的问题,但现在我无法删除它们。我被卡住了。

对于每个看着这个并问为什么的人。

在Exchange 2010 Service Pack 1(SP1)中,Exchange引入了一项功能,[强制]允许Outlook 2007和Outlook 2010客户端自动映射到用户具有完全访问权限的任何邮箱。如果用户被授予对其他用户的邮箱或共享邮箱的完全访问权限,则Outlook会自动加载用户具有完全访问权限的所有邮箱。

https://technet.microsoft.com/en-us/library/hh529943(v=exchg.141).aspx

当您拥有对其他林中的邮箱具有权限的邮箱时,这个可爱的小功能会导致问题。

答案 2 :(得分:0)

我想通了

 foreach($Mailbox in $Mailboxes){
    $FixAutoMappings = Get-MailboxPermission $Mailbox.DisplayName |where {$_.AccessRights -eq "FullAccess" -and $_.IsInherited -eq $false}
    $FixAutoMappings 
        Foreach($FixAutoMapping in $FixAutoMappings){
        Remove-MailboxPermission -Identity $Mailbox.Identity -User $FixAutoMapping.User -AccessRights $FixAutoMapping.AccessRights -confirm:$false
        Add-MailboxPermission -Identity $Mailbox.Identity -User $FixAutoMapping.User -AccessRights:FullAccess -AutoMapping $false
        }
}

这似乎对我有用。