Forum Discussion
Problem restoring deleted user with mggraph
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 $params
Ex2
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 $params
Both gives the same error for the BodyParameter, so most likely I am using this wrong somehow.
/Adam
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