remove all rights for a specific user on all  exchange mailboxes

Daoust ICT
Daoust ICT used Ask the Experts™
on
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"
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Rated Freelancer on MS Technologies
Awarded 2018
Distinguished Expert 2018
Commented:
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 : https://technet.microsoft.com/en-us/library/bb125153%28v=exchg.160%29.aspx?f=255&MSPPError=-2147217396
    Remove-MailboxPermission -identity $_.SamAccountName -User $str.SamAccountNAme -AccessRights $ar -InheritanceType All -confirm:$false
 }

Open in new window


Main source:
https://technet.microsoft.com/es-es/library/bb125153%28v=exchg.160%29.aspx?f=255&MSPPError=-2147217396


Posible errors:
https://social.technet.microsoft.com/Forums/en-US/50a94a45-903e-409e-ba5c-116d84bed7ff/cannt-remove-full-access-rights-for-one-user?forum=exchangesvrdeploylegacy
http://exchange-powershell.com/2010/06/03/exchange-cannot-remove-ace-on-object-because-it-is-not-present
http://clintboessen.blogspot.mx/2015/04/unable-to-remove-mailbox-permission-in.html
http://www.morgantechspace.com/2015/08/powershell-remove-full-access-permissions-from-mailbox.html
AlanConsultant
Commented:
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.

Alan.
Daoust ICTIcT service Desk

Author

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 CastroTop Rated Freelancer on MS Technologies
Awarded 2018
Distinguished Expert 2018

Commented:
It does

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial