We are in a hybrid Exchange environment. I am creating a script to create users and their associated remote mailboxes. After completing a successful run of the script, I deleted the test user without first removing the remote mailbox. Now, I have a remote mailbox with no AD user associated to it. When I attempt remove-remotemailbox it errors stating that it could not find the user in AD (because it had been deleted).
I tried recreating the AD user without enabling the remote mailbox, but I assume because it has a different GUID, it doesn't see it as the same AD user.
Office 365 Administration won't let me delete the account there -- the option is grayed out.
How can I get rid of this orphaned remote mailbox?
First of all, remove all assigned licenses to the Office 365 user; this will also get rid of the actual Exchange Online mailbox.
Then, you should delete the user account from the Entra ID administration portal; if it still won't let you do that because the user is seen as being synced from on-premises AD, you can forcibly delete it using PowerShell: https://learn.microsoft.com/en-us/microsoft-365/enterprise/delete-and-restore-user-accounts-with-microsoft-365-powershell.