1
votes

Via VS 2017 calling Setup.cmd which contains:

@echo off
chcp 65001
powershell -ExecutionPolicy Unrestricted .\setup.ps1 "%*"

The file is called, and this error appear:

Active code page: 65001
.\setup.ps1 : The term '.\setup.ps1' 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:1
+ .\setup.ps1 -SkipDbInstall:0 -SkipPandoSupportInstall:0 -SkipSearchServiceInstal ...
+ ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (.\setup.ps1:String) [], Command     NotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

setup.ps1 exist in the same level like setup.cmd.

What can be the problem?

3
Sometimes, .cmd files execute from the temp directory instead of the location they reside. Try to echo out the location and see if that is the case. - Sid

3 Answers

2
votes

Most likely your working directory is not what you think it is. You can verify that by adding a line echo %CD% to the batch file.

To change the working directory to the folder in which the scripts reside add a line cd /d "%~dp0". You also need to remove the quotes from %*, otherwise all arguments to your batch script will be passed as a single string argument to the PowerShell script. And I'd recommend using the parameter -File with powershell.exe, so that you'll get a proper exit code from the PowerShell script (if it returns one).

@echo off
cd /d "%~dp0"
chcp 65001 >nul
powershell.exe -ExecutionPolicy Unrestricted -File .\setup.ps1 %*

If the PowerShell script doesn't care about the working directory you could also run it with the full path instead of changing the directory:

powershell.exe -ExecutionPolicy Unrestricted -File "%~dp0setup.ps1" %*
1
votes

Sometimes you have to change the directory by yourself:

PowerShell -Command "cd \scripts; .\setup.ps1"
1
votes

My problem was that windows environment variable was pointing to 2 msbuild file locations on the file system, so when I ran the command msbuild in cmd - the wrong msbuild was called.

Deleting the wrong one and leaving the good one, in the windows environment variable - did the trick!