I have the following script in Powershell ISE.
cd E:\Data
@"
xxxx.zip
yyyy.zip
"@ -split "`n" | % { echo "'$_'"; test-path -path "$_" -EA Stop }
However it always raises error.
'xxxx.ZIP'
False
Illegal characters in path.
At line:175 char:27
+ % { echo "'$_'"; test-path <<<< -path "$_" -EA Stop }
+ CategoryInfo : InvalidArgument: (E:\Data\xxxx.ZIP:String) [Test-Path], ArgumentException
+ FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.TestPathCommand
However, I can run Test-Path -path xxxx.zip
or just hard code 'xxxx.zip' in the script and it runs fine. What's the problem of piped string?
Update
If I change the last script to % { echo "'$_'"; "test-path -path $_ -EA Stop" }
and copy/paste the output ("test-path -path xxxx.ZIP -EA Stop
") to the command line. It works.
Update
It seems it works in powershell console. An ISE bug?