Script to remove Exchange 2010 AutoMapping for all mailboxes
That is incredibly easy. You simply need to retrieve a list of mailboxes and run the example against each of them:
# Get all mailboxes in the forest
$Mailboxes = 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
$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
}
}