Forum Discussion
Problem restoring deleted user with mggraph
Hello,
I have done a few 365 migration and almost everytime there are some user data that has been missed in the migration.
Earlier I solved this by restoring the 365 user in the source tenant to another domain using this msol script in powershell:
Restore-MsolUser -UserPrincipalName email address removed for privacy reasons -Verbose
Restore-MsolUser -UserPrincipalName email address removed for privacy reasons -Verbose -AutoReconcileProxyConflicts
Restore-MsolUser -UserPrincipalName email address removed for privacy reasons -Verbose -AutoReconcileProxyConflicts -NewUserPrincipalName email address removed for privacy reasons
I know it is not perfect but it worked well and saved a bunch of times.
I have now done another migration now and got the same issue so I need to restore the users so we can access the data again and move it. BUT!
I realized today that msol service is no more, so I am kinda stuck with figuring this out in mggraph.
I have tried for a few hours now and I am not sure if this even possible with mggraph.
Whenever I try to build a script using Restore-MgDirectoryDeletedUser/Item which google, copilote etc tells me to use I only get this error:
The term 'Restore-MgDirectoryDeletedUser/item' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
Or I get that it "works" but that the proxy/domain conflicts:
Errors detected while trying to restore the user restoreUserErrors: ErrorValue:<pii><pii>E*****.E*******</pii>@domain.com</pii> ObjectType:
ConflictingObjectId:, ErrorType:UserPrincipalName, ErrorId:InvalidDomainErrorValue:<pii>smtp:<pii>ee</pii>@domain.com</pii> ObjectType: ConflictingObjectId:, ErrorType:ProxyAddress,
ErrorId:InvalidDomain
Status: 400 (BadRequest)
ErrorCode: Request_BadRequest
Date: 2025-09-08T13:49:36
Since I do not have the first domain in the source tenant anymore I need to restore the user to a different domain.
Does anyone have any idea on how I can recreate the msol version to mggraph? I feel like I have tried everything to my knowledge now so hopefully anyone here can give me help or tips.
Thanks!
/Adam
4 Replies
- AdamneedshelpwithpowershellCopper Contributor
Hi, thanks for the response.
I saw this yesterday aswell and I agree that it should work, but I get this error when I try to run it:
Restore-MgDirectoryDeletedItem : A parameter cannot be found that matches parameter name 'BodyParameter'.
I have tried both these variants:
C:\WINDOWS\system32> Import-Module Microsoft.Graph.Identity.DirectoryManagement
>>
>> $params = @{
>> autoReconcileProxyConflict = $true
>> }
>>
>> Restore-MgDirectoryDeletedItem -DirectoryObjectId e0995e5e-13d8-40eb-a29e-9***********733 -BodyParameter $paramsEx2
C:\WINDOWS\system32> Import-Module Microsoft.Graph.Identity.DirectoryManagement
>>
>> $params = @{
>> newUserPrincipalName = "E*********.E*********@newdomain.onmicrosoft.com"
>> }
>>
>> Restore-MgDirectoryDeletedItem -DirectoryObjectId e0995e5e-13d8-40eb-a29e-9**********33 -BodyParameter $paramsBoth gives the same error for the BodyParameter, so most likely I am using this wrong somehow.
/Adam
- LainRobertsonSilver Contributor
Hi Adamneedshelpwithpowershell,
It's not your fault. The example within the Microsoft documentation is incorrect.
Where the example lists the "-BodyParameter" parameter, it should have instead used the "-Headers" parameter. Quality assurance for the loss.
To provide some tangible evidence, the following screenshot shows the list of parameters for the 2.30.0 version of Restore-MgDirectoryDeletedItem where you can see there is no such parameter as "BodyParameter", but there is one named "Headers".
And here is an end-to-end example demonstrating the autoReconcileProxyConflict header from the documentation.
The commands - in order - show:
- A deleted user;
- Restoring the user whilst using the autoReconcileProxyConflict header;
- That the user can now be seen as a normal user once more;
- Deleted the user, sending it to the recycle bin (a soft delete);
- Deleted the user from the recycle bin (a hard delete).
Footnote: My examples use the beta endpoint commands but there's no difference with the v1.0 commands I referenced in my original reply.
Cheers,
Lain
- LainRobertsonSilver Contributor
Hi Adamneedshelpwithpowershell,
Use the Restore-MgDirectoryDeletedItem commandlet (from the Microsoft.Graph.Identity.DirectoryManagement module) in conjunction with the autoReconcileProxyConflict header:
- Restore-MgDirectoryDeletedItem (Microsoft.Graph.Identity.DirectoryManagement) | Microsoft Learn
- Restore deleted directory object item - Microsoft Graph v1.0 | Microsoft Learn
Cheers,
Lain
- AdamneedshelpwithpowershellCopper Contributor
Hi,
Thanks for the response, I looked at this yesterday and tried it aswell.
I think this should work, but it complains about the BodyParameter:
Restore-MgDirectoryDeletedItem : A parameter cannot be found that matches parameter name 'BodyParameter'.
So most likely I am using this wrong in some way, I tried doing these two ways:Import-Module Microsoft.Graph.Identity.DirectoryManagement$params = @{autoReconcileProxyConflict = $true}Restore-MgDirectoryDeletedItem -DirectoryObjectId e0995e5e-13d8-40eb-a29e-9d********733 -BodyParameter $params
Ex2:Import-Module Microsoft.Graph.Identity.DirectoryManagement$params = @{newUserPrincipalName = "E********.E*******@newdomain.onmicrosoft.com"}Restore-MgDirectoryDeletedItem -DirectoryObjectId e0995e5e-13d8-40eb-a29e-9***********3 -BodyParameter $params
Still get the same error with body parameter.
/Adam