Escaping chars in powershell is just silly. I’ve tried everything I can find to try and escape this pipe in a parameter that I’m passing into a powershell script, but I absolutely cannot escape it. It’s nuts. I make sure to pass the param in single quotes, and have tried all of the powershell/windows escape chars (`,“,\,\,^,^^). Any help is greatly appreciated.
Example of test script:
$cmd = $Args[0] #set first parameter received to $cmd to run with Invoke-Expression (must wrap param in single quotes if it contains spaces)
write-host $cmd
Calling test script with a pipe containing command:
C:\Windows\System32\cmd.exe /c powershell -executionPolicy Unrestricted -InputFormat none "D:\test_powershell\app\test_wrapper.ps1" 'test1 | test2'
Results:
'test2'' is not recognized as an internal or external command,
operable program or batch file.
A few notes:
cmd. Just call PowerShell directly.-InputFormatcan be either Text or XML.Noneis not a valid value here.Use the following (which is mentioned in the help too if escaping issues arise):