Run a powershell script exactly like a batch command
If you run stree.ps1
in PowerShell like this:
stree some_argument
then your stree.bat
should look like:
PowerShell -Command "stree some_argument"
See the documentation for more details.
Edit: I haven't tested it, but I assume you would pass the arguments in the same way as with any other batch script:
PowerShell -Command "stree %*"
and then run:
stree.bat some_argument some_other_argument
Edit 2: Ok, I tested it and it works like expected.
Related videos on Youtube
Ryan Leach
Updated on September 18, 2022Comments
-
Ryan Leach over 1 year
How can I get the effect of running a powershell script from a batch command.
e.g. I have a few batch commands on PATH specific to my user, I use these to make using the command line & git easier for my job.
However I havn't gotten into the habit of learning PowerShell yet, so don't like using PowerShell if I can help it.
However as stuff migrates, more and more scripts appear to be powershell scripts.
How can I create a 'shortcut' batch file, that forwards all arguments passed to it, to a powershell script of the same name?
E.g. I have a Powershell script called stree.ps1
Start-Process "C:\Users\ryan.leach\AppData\Local\SourceTree\SourceTree.exe" -ArgumentList "-f $((Resolve-Path $args[0]).toString())"
that will launch SourceTree with the argument corresponding to a passed in path.
How can I create a stree.bat that calls stree.ps1 forwarding all arguments to stree.ps1, without having to update stree.bat if small changes are made to stree.ps1?
-
Ryan Leach almost 6 yearsHow can you flow the arguments in? Hard coding is easy enough.
-
Konrad Botor almost 6 yearsI assume like in any other batch script - see my edit.