msgraph-sdk-powershell
msgraph-sdk-powershell copied to clipboard
Restore-MgBetaDirectoryDeletedItem missing BodyParameter parameter
Describe the bug
The Restore-MgBetaDirectoryDeletedItem cmdlet documents the use of the Bodyparameter parameter https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.beta.identity.directorymanagement/restore-mgbetadirectorydeleteditem?view=graph-powershell-beta to pass details of deleted object being restored with a different UPN. V2.27 of the cmdlet says that no such parameter can be found.
Expected behavior
$DeletedUserUPN = "[email protected]" $NewUserPrincipalName = "[email protected]" $DeletedObject = Get-MgDirectoryDeletedItemAsUser -Filter "displayName eq 'Marc Vigneau'" $NewUPNDetails = @{} $NewUPNDetails.Add("newUserPrincipalName",$NewUserPrincipalName) $NewUPNDetails.Add("autoReconcileProxyConflict",$true)
$Status = Restore-MgBetaDirectoryDeletedItem -DirectoryObjectId $DeletedObject.Id -BodyParameter $NewUPNDetails Restore-MgBetaDirectoryDeletedItem: A parameter cannot be found that matches parameter name 'BodyParameter'.
How to reproduce
See above.
SDK Version
V2.27
Latest version known to work for scenario above?
V2.25
Known Workarounds
Use Graph request
Debug output
No debug because cmdlet fails immediately
```</details>
### Configuration
Windows
Name Value
---- -----
PSVersion 7.5.1
PSEdition Core
GitCommitId 7.5.1
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
### Other information
_No response_
Updated to V2.28 and the Bodyparameter parameter is still unsupported.
The issue still exists in SDK V2.29. I note that the documentation has removed the BodyParameter parameter from the list of parameters, but still features BodyParameter in two of the examples such as https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.beta.identity.directorymanagement/restore-mgbetadirectorydeleteditem?view=graph-powershell-beta&WT.mc_id=M365-MVP-9501#example-3-restore-a-deleted-user-and-assign-them-a-new-userprincipalname
I can reproduce this issue. I had v2.25 running this commandlet successfully in PowerShell V7.5.2 env. After I upgraded the Graph SDK to 2.29 this error occurred.
@12Knocksinna in your original post, you mention "Known Workarounds Use Graph request."
can you share details on this workaround? I just ran a test using this restore option to prepare for a client migration and now that I'm rerunning the tests, they are now failing with the same error you are reporting. Thanks!
Here's the Graph API: https://learn.microsoft.com/en-us/graph/api/directory-deleteditems-restore?view=graph-rest-1.0&tabs=http
Why are you attempting to patch sites/users? You need to update the users resource...
From: z3r0th3h3r0 @.> Sent: Tuesday, August 12, 2025 8:56 PM To: microsoftgraph/msgraph-sdk-powershell @.> Cc: 12 Knocksinna (Gmail) @.>; Mention @.> Subject: Re: [microsoftgraph/msgraph-sdk-powershell] Restore-MgBetaDirectoryDeletedItem missing BodyParameter parameter (Issue #3318)
[https://avatars.githubusercontent.com/u/54514346?s=20&v=4]z3r0th3h3r0 left a comment (microsoftgraph/msgraph-sdk-powershell#3318)https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/3318#issuecomment-3180822197
Here's the Graph API: https://learn.microsoft.com/en-us/graph/api/directory-deleteditems-restore?view=graph-rest-1.0&tabs=http
Have you had any luck with this method? I am constantly getting errors. I've tried several variances of this:
Invoke-MgGraphRequest -method PATCH -uri "https://graph.microsoft.com/v1.0/sites/users/8d85da92-aef5-4f9c-ba54-395449cdf145" -body @{onPremisesImuttableId = $null}
but this is what I get no matter what I do (Patch/Post, quotes around the variable/no quotes):
HTTP/1.1 400 Bad Request Transfer-Encoding: chunked Vary: Accept-Encoding Strict-Transport-Security: max-age=31536000 request-id: f6b24f83-56ff-470c-b93d-6a124e2b41f6 client-request-id: 39633e93-6566-417e-a438-a120ac0a924a x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"West US 2","Slice":"E","Ring":"4","ScaleUnit":"001","RoleInstance":"MW2PEPF00011F87"}} Date: Tue, 12 Aug 2025 19:46:07 GMT Content-Type: application/json {"error":{"code":"BadRequest","message":"Resource not found for the segment '8d85da92-aef5-4f9c-ba54-395449cdf145'.","i nnerError":{"date":"2025-08-12T19:46:08","request-id":"f6b24f83-56ff-470c-b93d-6a124e2b41f6","client-request-id":"39633 e93-6566-417e-a438-a120ac0a924a"}}} At line:1 char:1
-
Invoke-MgGraphRequest -method PATCH -uri "https://graph.microsoft.comhttps://graph.microsoft.com/ ...
-
+ CategoryInfo : InvalidOperation: (Method: PATCH, ...ication/json
}:HttpRequestMessage) [Invoke-MgGraphRequest], HttpResponseException
- FullyQualifiedErrorId : InvokeGraphHttpResponseException,Microsoft.Graph.PowerShell.Authentication.Cmdlets.Invok eMgGraphRequest
Reply to this email directly, view it on GitHubhttps://github.com/microsoftgraph/msgraph-sdk-powershell/issues/3318#issuecomment-3180822197, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AK45CISRZGLBXA6URRU7QIT3NJBGXAVCNFSM6AAAAAB43H3YUCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTCOBQHAZDEMJZG4. You are receiving this because you were mentioned.Message ID: @.@.>>
Sorry I hit reply on the wrong post.
Why are you attempting to patch sites/users? You need to update the users resource...
From: z3r0th3h3r0 @.> Sent: Tuesday, August 12, 2025 8:56 PM To: microsoftgraph/msgraph-sdk-powershell @.> Cc: 12 Knocksinna (Gmail) @.>; Mention @.> Subject: Re: [microsoftgraph/msgraph-sdk-powershell] Restore-MgBetaDirectoryDeletedItem missing BodyParameter parameter (Issue #3318)
[https://avatars.githubusercontent.com/u/54514346?s=20&v=4]z3r0th3h3r0 left a comment (microsoftgraph/msgraph-sdk-powershell#3318)<#3318 (comment)>
Here's the Graph API: https://learn.microsoft.com/en-us/graph/api/directory-deleteditems-restore?view=graph-rest-1.0&tabs=http
Have you had any luck with this method? I am constantly getting errors. I've tried several variances of this:
Invoke-MgGraphRequest -method PATCH -uri "https://graph.microsoft.com/v1.0/sites/users/8d85da92-aef5-4f9c-ba54-395449cdf145" -body @{onPremisesImuttableId = $null}
but this is what I get no matter what I do (Patch/Post, quotes around the variable/no quotes):
HTTP/1.1 400 Bad Request Transfer-Encoding: chunked Vary: Accept-Encoding Strict-Transport-Security: max-age=31536000 request-id: f6b24f83-56ff-470c-b93d-6a124e2b41f6 client-request-id: 39633e93-6566-417e-a438-a120ac0a924a x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"West US 2","Slice":"E","Ring":"4","ScaleUnit":"001","RoleInstance":"MW2PEPF00011F87"}} Date: Tue, 12 Aug 2025 19:46:07 GMT Content-Type: application/json {"error":{"code":"BadRequest","message":"Resource not found for the segment '8d85da92-aef5-4f9c-ba54-395449cdf145'.","i nnerError":{"date":"2025-08-12T19:46:08","request-id":"f6b24f83-56ff-470c-b93d-6a124e2b41f6","client-request-id":"39633 e93-6566-417e-a438-a120ac0a924a"}}} At line:1 char:1
Invoke-MgGraphRequest -method PATCH -uri "https://graph.microsoft.comhttps://graph.microsoft.com/ ...
+ CategoryInfo : InvalidOperation: (Method: PATCH, ...ication/json
}:HttpRequestMessage) [Invoke-MgGraphRequest], HttpResponseException
- FullyQualifiedErrorId : InvokeGraphHttpResponseException,Microsoft.Graph.PowerShell.Authentication.Cmdlets.Invok eMgGraphRequest
Reply to this email directly, view it on GitHub<#3318 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AK45CISRZGLBXA6URRU7QIT3NJBGXAVCNFSM6AAAAAB43H3YUCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTCOBQHAZDEMJZG4. You are receiving this because you were mentioned.Message ID: @.@.>>
Oh, I know exactly what the root cause is here.
There's a whole lot of directory APIs that have added new optional body parameters to requests which previously did not have a body.
This creates a breaking change in the dotnet and other strongly typed languages as the underlying method had to be changed from one without a body parameter, to one with a body parameter. There's an issue tracking issue here: https://github.com/microsoft/OpenAPI.NET.OData/issues/582
Because this would be a breaking change for most of the SDKs the metadata that we use to produce the SDKs does not have the body parameters included.
The workaround for PowerShell is to use the underlying API directly via Invoke-MgGraphRequest