Forum Discussion
Facing error when running a ps script using mggraph
- Aug 29, 2024
Hi.
Your second and third Invoke-RestMethod URIs don't look properly formatted to me, going off what you've pasted in this thread.
Because the strings are using double-quotes, PowerShell will parse breakout characters like $ and ? instead of interpreting them literally.
I haven't bothered running a real test as there's no need. In the examples below, the only thing we're interested in is the parsed URI in yellow. Here, you can see that based on your code, you're not going to get the URI you think you're getting (first example) unless you remember to escape the special characters (second example).
Cheers,
Lain
Hi.
Your second and third Invoke-RestMethod URIs don't look properly formatted to me, going off what you've pasted in this thread.
Because the strings are using double-quotes, PowerShell will parse breakout characters like $ and ? instead of interpreting them literally.
I haven't bothered running a real test as there's no need. In the examples below, the only thing we're interested in is the parsed URI in yellow. Here, you can see that based on your code, you're not going to get the URI you think you're getting (first example) unless you remember to escape the special characters (second example).
Cheers,
Lain
- vrush96Aug 29, 2024Copper ContributorI tried to escape the special characters still i get 404 error
- LainRobertsonAug 29, 2024Silver Contributor
Perhaps use the -Verbose parameter as I have in the examples above on the second and third Invoke-RestMethod calls so you can see what the final URI looks like and validate that it matches the required format.
Until we know for sure that the URI is valid, there's no point in looking any further.
Cheers,
Lain
- vrush96Aug 30, 2024Copper Contributor
Hi LainRobertson,
Thanks for your help idea of using verbose did the trick and the url helped me is "https://graph.microsoft.com/v1.0/users/$($userId)?`$select=signInActivity"