0
votes

I have written a powershell script that I'd like to be able to run from a batch script on Windows.

The powershell script is located in blizzard-main.ps1.

The CMD script looks like this:

@ECHO OFF
powershell -command "& { . %~dp0%\blizzard-main.ps1; Blizzard-Main %1}"
:EOF

The strange error I get when running this is:

. : The term 'C:\Users\mzr\Documents\GitHub\ProductionTools\Blizzard\Dist\Blizzard\bin\1'
is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.

At line:1 char:7

+ & { . C:\Users\mzr\Documents\GitHub\ProductionTools\Blizzard\Dist\Blizzard\bin\1 ...
[SNIP]

If I debug the script using echo like this:

@ECHO OFF
ECHO powershell -command "& { . %~dp0%\blizzard-main.ps1; Blizzard-Main %1}"
:EOF

I get this interesting output:

powershell -command "& { . C:\Users\mzr\Documents\GitHub\ProductionTools\Blizzard\Dist\Blizzard\bin\1}"

So clearly something has been messed up. If I remove the %1, the script is executed, but then the first parameter isn't being passed the way it should.

2

2 Answers

1
votes

I found the error myself:

@ECHO OFF
ECHO powershell -command "& { . %~dp0%\blizzard-main.ps1; Blizzard-Main %1}"
:EOF

should be changed to

@ECHO OFF
ECHO powershell -command "& { . %~dp0\blizzard-main.ps1; Blizzard-Main %1}"
:EOF

(I had an extra %.)

0
votes

Remember that the %~dp0 includes a trailing slash, so you may not want to add yet another trailing slash onto it. Also, I'd recommend always putting double quotes around the path to a file, just in case there's a space in the path.

Change your command line to this:

powershell -command "& { . \"%~dp0%blizzard-main.ps1\"; Blizzard-Main %1}"