Default M365 Tenant Cleanup Script

The default M365 Tenant Cleanup script is shown below. This script removes the scripts configured with Location Based Routing, M365 onboarding with LBR and custom networks and M365 default onboarding using SBC Site name.

This script is hard-coded and is not included in the SQL database.

Copy
# Begin of Microsoft cleanup script

    # Remove the PSTN Gateway from the CsOnlineVoiceRoutes

    Get-CsOnlineVoiceRoute | Where-Object {$_.OnlinePstnGatewayList -like "{{SBC.OnlinePstnGateway}}"} | ForEach-Object {Set-CsOnlineVoiceRoute -Identity $_.Identity -OnlinePstnGatewayList  @{remove="{{SBC.OnlinePstnGateway}}"}}

    #Remove CsOnlineVoiceRoutes when OnlinePstnGatewayList is empty

    Get-CsOnlineVoiceRoute | Where-Object {$_.OnlinePstnGatewayList.count -eq 0} | Remove-CsOnlineVoiceRoute

    # End of M365 cleanup script;

Custom variables can be applied to this script in a similar manner to the SBC scripts.