Restore a M365 user with a different UPN via Graph Powershell?

Hello everyone!

I have now managed to restore M365 several times using MS Graph Powershell:

Restore-MgDirectoryDeletedItem -DirectoryObjectId $directoryObjectId

What I haven’t figured out yet is how to manage to restore the user with a different UPN. I often have this case, if for example the original domain is no longer there or a user with the same name is already active.

Does anyone of you know how to do this?

I am looking forward to your answers.

Best regards
compukortschnoi

Might be something to ask on an Office 365 admin forum. If there is a GUI method to do it, there is likely a PS way to do it.

1 Like

The GUI gives the same error as the cmdlet.

You can’t modify the properties of a soft-deleted user so I’m not sure how you would ever resolve the conflict without modifying the active user first.

I think you might have to approach this from the other direction, given that users are only soft-deleted for 30 days before being permanently removed.

i.e. you check for deleted users before you provision a new account, and if there’s a duplicate UPN you use a different UPN for your new user.

Likewise, before deleting a domain, you check deleted users to make sure there are no users that are still using it.

Hello you two,

thank you very much for your answers.

@matt-bloomfield: Thanks for your suggestions on workarounds. :slightly_smiling_face: Currently, I will have no other choice.

I am still a little annoyed. Why does one abolish a module if the replacement module or its cmdlets don’t have the range of functions that the old one had?

It is not an unlikely use case that a domain is removed from a tenant and later a user has to be restored that was created with this domain. Both the Admin Center and Powershell will not be able to do this, but will acknowledge it with an error message. Dead end.

Kind regards,
compukortschnoi

Have you looked at InputObjectId …

Hello @tonyd,

Among the parameters of InputObject, I did not find one that deals with the UPN. Did you manage to change the UPN of a user to be restored this way? Then I am very interested in your solution.

Kind regards,
compukortschnoi

No I did not. It was just a suggestion in case you had not looked there. Although the parameter values dont directly reference a “UPN” … if it were me, I would at least give some a try and was wondering if you had played around with some of the options for that parameter.

This article does mention restoring via UPN, but using a different command.

1 Like

Hello @tonyd,

Thank you so much for googling for me.

However, the fact that I want to go the Graph Powershell route to restore the user has to do with the fact that the modules and cmdlets used in the article you mentioned will soon be unavailable.

Kind regards,
compukortschnoi

Understood … if you find a solution, please post in case others can benefit.