Escaping Spaces

Escaping Spaces

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

Old Cmd S In Powershell

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License