Escaping Spaces

by Nov 4, 2010

You should remember that spaces are special characters in PowerShell, too. They are token delimiters, and once you feed arguments to a native command, PowerShell will separate arguments by space and feed the individual arguments one by one to the native command. Why does this work in cmd.exe and not in powershell.exe?

Find /I "dir" *.ps1

Here is your answer:

Trace-Command NativeCommandParameterBinder {find /I "dir" *.ps1} -pshost

Actually, find.exe expected two parameters, not three. The first two parameters should stay together. You can get this done by removing the space in between:

Find /I` "dir" *.ps1

Twitter This Tip!
ReTweet this Tip!