Commands useful when off-boarding a user

Prerequisites

These commands require the following modules:

Process

Get the user

$Username = (get-ExoRecipient "[email protected]").PrimarySmtpAddress

Disable Exchange Activesync

Set-CASMailbox -Identity $Username -ActiveSyncEnabled $false -OWAforDevicesEnabled $false -PopEnabled $False -ImapEnabled $False -OWAEnabled $False -EWSEnabled $False -MAPIEnabled $False -OutlookMobileEnabled $false

Give another user access to the mailbox

Add-MailboxPermission -Identity $Username -User "[email protected]" -AccessRights FullAccess

Sign out all applications and devices

Revoke-MgUserSignInSession -UserId $Username

Convert mailbox to shared

Set-Mailbox -Identity $Username -Type Shared

Remove all mobile devices on the server

Get-MobileDeviceStatistics -Mailbox $Username | Remove-MobileDevice

Set OOO Message

$OoOMessage = "User is no longer with Company. Please contact [email protected]."
Set-MailboxAutoReplyConfiguration -Identity $Username -AutoReplyState Enabled -InternalMessage $OoOMessage -ExternalMessage $OoOMessage

Cancel reoccurring Appointments

The mailbox must still exist in the tenant for this to work

Remove-CalendarEvents -Identity [email protected] -CancelOrganizedMeetings