3

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?

1
  • 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. Commented Sep 6, 2017 at 12:32

3 Answers 3

3

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" %*
Sign up to request clarification or add additional context in comments.

2 Comments

tried the 1st example and getting this: setup.ps1 : Cannot process argument transformation on parameter 'SkipDbInstall'. Cannot convert value "System.String" to type "System.Boolean". Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or 0. + CategoryInfo : InvalidData: (:) [setup.ps1], ParentContainsErro rRecordException + FullyQualifiedErrorId : ParameterArgumentTransformationError,setup.ps1
That is a problem with the parameter handling of your PowerShell script. Basically, when invoking PowerShell scripts from outside PowerShell all arguments are strings. That's a different question, though, and should be posted as such.
1

Sometimes you have to change the directory by yourself:

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

Comments

1

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!

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.