Powershell – Safest way to run BAT file from Powershell script

batch-filepowershell

I can not get a powershell script to execute a bat file directly. For example, this works on the command line:

.\\my-app\my-fle.bat

When I add this command to a script, it outputs:

The term '.\\my-app\my-file.bat' 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.

I also tried the following, with the same result:

& .\\my-app\my-fle.bat
& ".\\my-app\my-fle.bat"
\my-app\my-fle.bat
& \my-app\my-fle.bat
& "\my-app\my-fle.bat"

Note: It must return the lastexitcode as I need to verify success of batch.

Best Answer

cmd.exe /c '\my-app\my-file.bat'