I wanted to create some clickable PowerShell scripts, and I found this answer that I modified slightly to be:
;@Findstr -bv ;@F %0 | powershell -noprofile -command - & goto:eof
# PowerShell Code goes here.
I understand Findstr
is passing all lines that don't begin with ;@F
to the right-hand side of the pipe and the dash specifies where the input should go, but what is the dash character called and where is it documented?
I found an explanation of CMD's pipe operator on Microsoft's Using command redirection operators, but it doesn't mention anything about the dash character.
I presume you mean the
-
that precedes the&
. It has nothing to do with the pipe operator, it is a directive for powershell.Here is a description of the -Command option excerpted from powershell help (accessed by
powershell /?
)BTW - I did not realize FINDSTR accepted
-
as an option indicator until I saw your question. I've only seen and used/
. Good info to know.The
-
is to Powershell saying accept the command(s) from stdin rather than from arguments. This is not a feature in cmd / batch and piping. It would work with<
as well.Powershell version 2 adds a "Run with Powershell" right-click context menu item to run scripts . Here you'll find some enhanced shell extensions to run Powershell scripts with elevated privileges. However if you just want to run a Powershell script by double clicking a file, I recommend just calling the Powershell script from a batch script instead of trying to embed Powershell code in the batch script. In the batch script use this:
powershell.exe -file "%~dp0MyScript.ps1"
where%~dp0
expands to the current directory. This essentially creates a bootstrapper for your Powershell script that you can double click to launch your Powershell script.