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 powershell.org forum. What he suggested was to create a proxy function around [Invoke-RestMethod](http://technet.microsoft.com/en-us/Library/hh849971.aspx) 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](http://technet.microsoft.com/en-us/Library/hh849971.aspx) 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](http://technet.microsoft.com/en-us/Library/hh849971.aspx) proxy function:

References