In an earlier post, I wrote about how to setup auto-forwarding for a user’s email if they are on an extended leave from the office. One of the interesting problems that has arisen once that employee returned was that their email folder was still showing up in my list of mailboxes in Outlook 2016, even after the forward was disabled and delegate access was confirmed as being removed/never setup in the first place.

Resolving the issue involves a little bit of Powershell, and while the script code isn’t terribly difficult, I did have to piece it together from a couple of different sources and deal with the fact that I had MFA (multi-factor authentication) enabled on my account.

In the end, I disabled MFA briefly on my account while I executed the script below. I was unsuccessful being able to connect to Exchange Online via Powershell with MFA and gave up because I didn’t think it was worth my time to troubleshoot for something that was fairly insignificant for my use case.

Below is the script I used:

#Must disable MFA in order for this to work. Otherwise, there are supposedly ways to get MFA to work with this script, but I wasn't successful with them
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
Remove-MailboxPermission -Identity <MailboxToRemove> -User <UserWhoWantsMailboxRemoved> -AccessRights FullAccess
Add-MailboxPermission -Identity <MailboxToRemove> -User <UserWhoWantsMailboxRemoved> -AccessRights FullAccess -AutoMapping:$false
Remove-PSSession $Session