Forum Discussion
Facing error when running a ps script using mggraph
- 2 years ago
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
- vrush962 years agoCopper ContributorI tried to escape the special characters still i get 404 error
- LainRobertson2 years agoSilver 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
- vrush962 years agoCopper 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"