Invoke-RestMethod cmdlet proxy – more on un-escaping forward slashes in URIs

Mariusz Wojcik

Recently I posted an article showing how to prevent Invoke-RestMethod from unescaping dots and slashes. Soon after that I got a great advice from Dave Wyatt, moderator for forum. What he suggested was to create a proxy function around [Invoke-RestMethod]( cmdlet which will disable UnEscapingDotsAndSlashes when the call is made. After some reading about proxy functions in PowerShell 1 2 (I couldn’t believe how easy it is to create proxy function in PowerShell) I decided on creating a proxy function which will extend [Invoke-RestMethod]( cmdlet with an extra parameter AllowEscapedDotsAndSlashes. Setting it to true will disable UnEscapingDotsAndSlashes for the time the call to the server is made and then switch back to original setting. This approach restricts intrusion to selected call only, minimising chances of breaking other existing code.

You would use it as follow:

Invoke-RestMethod proxy function

Below is the code of [Invoke-RestMethod]( proxy function: