Reputation: 35843
I would like to execute powershell commands from a Windows console commandline. My method is:
c:\>powershell -Command mypowershellstatment1;mypowershellstatment1;etc
Issue:
In case if a complex powershell command contains powershell pipe operator, then it seems that Windows console interprets it, instead of passing it literally as parameter to the powershell executable.
For example:
c:\>powershell -Command mypowershellstatment1 | anything;mypowershellstatment1;etc
gives the standard console error message "'anything' is not recognized as an internal or external command" operable program or batch file.
Question
How to overcome this issue?
Upvotes: 0
Views: 1828
Reputation: 174485
Since |
has a similar function in cmd, you need to escape it.
In cmd, the appropriate escape sequence would be ^|
:
C:\>powershell -Command Get-Something ^| Do-Something
Upvotes: 3
Reputation: 187
powershell "command1 | command2 | command3... | commandN-1 | commandN"
Upvotes: -1