簡體   English   中英

Powershell - Exchange - 刪除幾乎所有郵箱權限

[英]Powershell - Exchange - Remove almost all mailbox 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

知道如何解決這個問題嗎?

一個快速而骯臟的解決方案可能是這樣的:

$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 顯示將要執行的操作,供管理員在將腳本啟動到生產環境之前查看。

約翰,

我遇到了完全相同的問題。

我做了一個改變,它把問題推倒了,但沒有解決它。


$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

當您的郵箱有權訪問不同林中的郵箱時,這個可愛的小功能會導致問題。

我想到了

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

這似乎對我有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM