0

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 :(

1
  • 1
    Please review How to Ask and minimal reproducible example. It would have been easier on everyone if you had shown the resulting ps1 file and explained what you wanted it to contain. Commented Dec 23, 2017 at 23:58

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.