Messages tagged with PowerShell

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 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.

Why you should not add you PowerShell modules to Windows directory

In his presentations Getting Started with PowerShell 3.0 Jump Start & Advanced Tools & Scripting with PowerShell 3.0 Jump Start, Jason Helmick stresses that you should never put you PowerShell module in Windows directory (usually c:\windows\system32\WindowsPowerShell\…) but he doesn’t give a good explanation why you should not do that. I though that it may be useful for some people to understand why it is not such a good idea to do it.

How to prevent Invoke-RestMethod from un-escaping forward slashes

You may also want to read Invoke-RestMethod cmdlet proxy – more on un-escaping forward slashes in URIs

While working on RabbitMQTools module I came across a problem with un-escaping forward slashes in Urls by [Invoke-RestMethod](http://technet.microsoft.com/en-us/Library/hh849971.aspx) cmdlet. The default Virtual Host on RabbitMQ is called "/" and when invoking Api methods it must be encoded with %2f:

Working with REST services in PowerShell

With PowerShell 3.0 comes a wonderful Invoke-RestMethod cmdlet which much simplifies using REST services. The cmdlet handles all communication as well as data serialisation/deserialisation. Below gist shows how easy it is to make a call to get some data from the REST service:

Depending on the result type (atom, JSON, XML), the cmdlet will appropriately deserialise data and return richly object (or collection of objects).

Learning PowerShell

For some time now I wanted to learn PowerShell. I have seen some samples on the internet, even used one or two but never had a chance to sit down and learn it. Until now. Recently I have joined Microsoft Virtual Academy and one of the first modules I did was Getting Started with PowerShell 3.0 Jump Start followed by Advanced Tools & Scripting with PowerShell 3.0 Jump Start. Both modules are run by Jason Helmick and Jeffrey Snover.

First module introduces PowerShell and explains some basics, such as getting help, how to use pipeline or remoting. It has enough information to start using PowerShell as a consumer. I must say that as a developer I found it very useful, especially part about remoting. The second module goes deeper into the power of PowerShell and is mostly about extending it with own functions or modules. If you are thinking about creating some custom cmdlets, you have to watch this module. As a matter of fact, the material covered in the jump starts was enough for me to go and start creating my own module RabbitMQTools for administering RabbitMQ servers. During next few months I plan to share my discoveries related to writing PowerShell modules, so keep watching my blog.

For anyone who wants to start using PowerShell I strongly recommend watching those modules.