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

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:


1 Extending and/or Modifing Commands with Proxies

2 Proxy Functions: Spice Up Your PowerShell Core Cmdlets


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s