Hello! Blog is just starting!
Keep your ear to the ground!
New posts are coming!

26th SEPTEMBER 2014

PowerShell and command line quotes- surprise!

Version: Powershell 3.0

Calling PowerShell from Windows command line

If you want to call any PowerShell script passing parameters there are at least two ways to do that.

From PowerShell console:

Or from windows command line:

Hereby I say, syntax of the second one is wrong and may lead to serious problems in business.

What happens in the second case then?

All the parameters are being passed to windows console and parsed. For cmd.exe doule quote means moreover „do not split” or „keep it together”. In this case it has no meaning at all. Powershell will receive only:

And this are four parameters!

By the way, do you know PowerShell Community Extensions? This toolset contains EchoArgs which I find useful in case of proper parameters passing check. Just replace application/script name with EchoArgs.

And here we go! The first example:

And the second one: (the wrong one)

A good practice

In my opinion a good solution is to use single quotes when passing parameters to PowerShell from Windows command line and double-single-quotes for passing apostrophe.