remove all rights for a specific user on all exchange mailboxes

Is this a statement state of the art?
#Remove permission to all mailboxes for user $strUser
Get-MailboxDataBase | Remove-MailboxPermission -User $strUser -AccessRights FullAccess
#Remove SendOnBehalf of right to all mailboxes for user $strUser
Get-MailboxDatabase | Remove-ADPermission -User $strUser -ExtendedRights "send as"
François VDCIcT service DeskAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jose Gabriel Ortega CastroEE Solution Guide/Topic Advisor and CEO Faru Bonon ITCommented:
So what's the question?

 $str = Get-mailbox -identity <Username>
 $ar = "FullAccess", "SendAs", "ExternalAccount", "DeleteItem", "ReadPermission", "ChangePermission", "ChangeOwner"
 Get-mailbox -filter * |ForEach-Object{
    Write-Output "Removing permissions for $($str.SamAccountName) in MBX $($_.SamaccountName)"
    #reference :
    Remove-MailboxPermission -identity $_.SamAccountName -User $str.SamAccountNAme -AccessRights $ar -InheritanceType All -confirm:$false

Open in new window

Main source:

Posible errors:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hi François,

It will depend on how well the environment has been setup and managed.

Hopefully, at no point, have any permissions been granted directly to a user object, only to security groups.

If so, then removing all access from a user is easy - you just pull up which groups they are a member of, and remove the ones that you don't want them to have any more.

If the setup has not been managed this way, you may find that permissions have been granted directly to the user.  In an edge case, the person doing this might have documented everything (not ideal, but okay from a professional perspective), but if not you will need to track down all of those occurrences and remove them one at a time.

If you do have to do this, at the very least, make sure the 'owners' of the environment implement procedures so that the practice stops immediately - it won't help with the past mess, but it will mean it doesn't get any worse.

François VDCIcT service DeskAuthor Commented:
@Alan ; No, it's not the case. Security has been set to user object. The main reason is the autoload of shared mailbox into Outlook. putting people into group do not work with autoload of sharedmailbox....

@Jose Ortega : question is does the statements will do the job they are supposed to do [REMOVE RIGHT FOR USER $strUser to ALL MAILBOXES AND SUPPRESS SEND ON BEHALF RIGHT FOR $strUser to ALL MAILBOXES AND, is it the best manner to do it.
Jose Gabriel Ortega CastroEE Solution Guide/Topic Advisor and CEO Faru Bonon ITCommented:
It does
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.