Darknat
Darknat

Reputation: 21

Bat echo output code PowerShell

I have a bat script with this line :

echo ($a = (quser) -replace "\s{2,}" , ";" | Select-String -pattern console -notmatch | Select-string -pattern ID -notmatch)>>ScriptV3.ps1 

but when I launch this line, my bat search to recognize pipe |, but here, pipe are to my PowerShell script.

How can I hidden this pipe for my batch script but i find this pipe in my PowerShell script.

Thank you !

PS : if I write :

echo "$a = (quser) -replace "\s{2,}" , ";" | Select-String -pattern console -notmatch | Select-string -pattern ID -notmatch">>ScriptV3.ps1 

with quote, work in batch but doesn't work in PowerShell :(

Upvotes: 0

Views: 522

Answers (1)

npocmaka
npocmaka

Reputation: 57252

try with

echo ($a = (quser) -replace "\s{2,}" , ";" ^| Select-String -pattern console -notmatch ^| Select-string -pattern ID -notmatch)>>ScriptV3.ps1 

pipe redirection is with higher priority than the echo and needs to be escaped.

Upvotes: 1

Related Questions