Install and connect to Azure ad by using below two commands

Install-Module -Name MSonline
$msolcred = get-credential

connect-msolservice -credential $msolcred

To stop AADConnect sync use below command

Set-MsolDirSyncEnabled -EnableDirSync $false

Once you set the sync to disabled now you can delete user account by force for example in my lab i have few users to delete by force i use below commands

Remove-MsolUser –UserPrincipalName user1@Learninmylab.com -force
Remove-MsolUser –UserPrincipalName bob@Learninmylab.com -force
Remove-MsolUser –UserPrincipalName Chris@learninmylab.com -force
Remove-MsolUser –UserPrincipalName Sync_INHYD-DC01_7b4f13f1d455@Intunedemolab001.onmicrosoft.com -force
Remove-MsolUser –UserPrincipalName rob@learninmylab.com -force
Remove-MsolUser –UserPrincipalName SCCMADMIN@Learninmylab.com -force
Remove-MsolUser –UserPrincipalName AZAdmin@Learninmylab.com -force

To remvoe Groups
$GroupId = Get-MsolGroup -SearchString “MyGroup”

Remove-MsolGroup -objectid $GroupId

 

In case if you have a contact please use Remove-MsolContact

 

Leave a Reply