Skip to content

Instantly share code, notes, and snippets.

@msmorul
Created December 6, 2016 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msmorul/4d716acd3022ac543be80e441ddfbba5 to your computer and use it in GitHub Desktop.
Save msmorul/4d716acd3022ac543be80e441ddfbba5 to your computer and use it in GitHub Desktop.
$user = "NT User:S-1-5-21-579602563-1105609867-1454996784-1641"
$mailbox = "someuser@contoso.com"
$folders = @(Get-MailboxFolderStatistics $mailbox | Where {!($exclusions -icontains $_.FolderPath)} | Select FolderPath)
foreach ($origFolder in $folders) {
$id = $mailbox + ":" + $origFolder.FolderPath.Replace('/','\')
# Uncomment this to list all unattached sids
# get-MailboxFolderPermission -Identity $id | where {$_.user -like "*S-1-5*"}
# Remove dead permissions
if ($perm = get-MailboxFolderPermission -Identity $id -user $user -ErrorAction SilentlyContinue) {
remove-MailboxFolderPermission -Identity $id -user $user -Confirm:$false -ErrorAction STOP
write-host "Removed $id " + $perm.User
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment