Script to remove AutoMapping from select or all users in Exchange

An adeptation of the script by Matthias R Jessen.

# Get all mailboxes in the forest
$Mailboxes = Get-User -OrganizationalUnit "Employees" | Get-Mailbox -ResultSize unlimited -IgnoreDefaultScope
$ConfirmPreference = "None"

# Iterate over each mailbox
foreach($Mailbox in $Mailboxes)
{
    try 
    {
        # Try to run the example fix against the current $Mailbox
        $FixAutoMapping = Get-MailboxPermission $Mailbox |where {$_.AccessRights -eq "FullAccess" -and $_.IsInherited -eq $false}
        $FixAutoMapping | Remove-MailboxPermission -Confirm $false
        $FixAutoMapping | ForEach {Add-MailboxPermission -Identity $_.Identity -User $_.User -AccessRights:FullAccess -AutoMapping $false} 
    }
    catch
    {
        # Inform about the error if unsuccessful
        Write-Host "Encountered error: $($Error[0].Exception) on mailbox $($Mailbox.DisplayName)" -ForegroundColor Red
    }
}

This still cycle through all inboxes in the “Employee” UO and remove all AutoMapping from those shares. Please note that I disabled confirmation of privilege changes on the Remove-MailboxPermissions.

Leave a Reply

Your email address will not be published. Required fields are marked *