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?
Jose Gabriel Ortega CConnect With a Mentor CEO J0rt3g4 Consulting ServicesCommented:
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:
AlanConnect With a Mentor ConsultantCommented:
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 CCEO J0rt3g4 Consulting ServicesCommented:
It does
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.