How to Hide User from Global Address List

This script Removes the user from all Azure AD groups, all Teams, and all Distribution groups, Hides the user from the Exchange Global Address List , Converts the user to a shared mailbox, Removes the licenses, and prints which license it removed for canceling

Syntax

#########User info######
$userToOffboard = “olduser@oldclient.com”
$CustomerDefaultDomainname = “MyClient.onmicrosoft.com”
######### Secrets #########
$ApplicationId = ‘ApplicationID’
$ApplicationSecret = ‘ApplicationSecret’ | ConvertTo-SecureString -Force -AsPlainText
$RefreshToken = ‘RefreshToken’
$ExchangeRefreshToken = ‘ExchangeToken’
$UPN = “UPN-Used-to-Generate-Tokens”

Download Full Script

Share Script:

Purpose:This script will help of o365 user offload/ remove to o365.
Modification:Username needs to be changed
Type:M365
Compatibility:Cloud Only
Tags:
Reference link: