I'm having a really frustrating issue with a Microsoft Graph PowerShell command that I pulled straight from the Microsoft documentation. The specific command is `Restore-MgBetaDirectoryDeletedItem`, which I found in their example. But when I try to run it, I keep getting an error about a missing parameter: `A parameter cannot be found that matches parameter name 'BodyParameter'`. This is the part where it breaks down:
```
Restore-MgBetaDirectoryDeletedItem -DirectoryObjectId $directoryObjectId -BodyParameter $params
```
I've attempted running this command in PowerShell ISE, Windows PowerShell, and even PowerShell 7. Is this just a documentation error on Microsoft's part? What's the deal with the '-BodyParameter' issue?
2 Answers
Yeah, it looks like the documentation is off. You can check the actual syntax by using `Get-Command Restore-MgBetaDirectoryDeletedItem -Syntax` in your PowerShell. The real parameter set doesn't include `-BodyParameter`, which is why you're facing that error. Just try running that command, and it should clarify the parameters you need to use!
I ran into that same issue last week! Instead of using the broken command, I just sent an HTTP POST request to the Microsoft Graph endpoint directly: `https://graph.microsoft.com/v1.0/directory/deleteditems//restore` and added the body parameters there. It worked seamlessly for me!
Absolutely, that's a solid workaround! I just implemented something similar using `Invoke-MGGraphRequest` to handle it too. It's a bit of an extra step, but it does the trick.