Came across this today on a customers site. Basically there was a need to delete an external users account from Office 365 AD. According to this MS article the process is pretty straight forward.
However when I come to delete the account using the PowerShell below….
Remove-MsolUser -UserPrincipalName ‘a.user_domain.comt#EXT#@company.com’ -RemoveFromRecycleBin
…I hit an error:
Remove-MsolUser : User Not Found. ‘a.user_domain.comt#EXT#@company.com’
I knew this was rubbish as I could see it when I ran the command:
Get-MsolUser –ReturnDeletedUsers
The odd thing was I could delete normal Office 365 accounts with no issues, the article here didn’t help
So, how to fix.
Run the command
Get-MsolUser –ReturnDeletedUsers | select UserPrincipalName, ObjectId
You’ll now have a objectID related to the email you’re trying to delete. Use this objectID to remove the account
Remove–MsolUser –RemoveFromRecycleBin –ObjectId <objected>
Hey-presto the account is removed.
Argh! IT is fun sometimes.