Why Native Commands Fail In PowerShell

by Nov 3, 2010

You probably already know that not all native commands work equally well in PowerShell. Have a look here:

find /I /N "dir" *.ps1

In cmd.exe, this line finds all occurrences of "dir" in all PowerShell scripts that are located in the current path. In PowerShell, the very same command will fail because special characters can confuse the PowerShell parser.

" The beginning (or end) of quoted text
# The beginning of a comment
$ The beginning of a variable
& Reserved for future use
( ) Parentheses used for sub-expressions
{ } Script block
| Pipeline separator
` Escape character

One workaround is to execute the line in good old cmd.exe and then enclose the command in single quotes:

cmd.exe /c 'find /I /N "dir" *.ps1'

Twitter This Tip!
ReTweet this Tip!