Safest way to run BAT file from Powershell script Safest way to run BAT file from Powershell script powershell powershell

Safest way to run BAT file from Powershell script


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


To run the .bat, and have access to the last exit code, run it as:

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


Try this, your dot source was a little off. Edit, adding lastexitcode bits for OP.

$A = Start-Process -FilePath .\my-app\my-fle.bat -Wait -passthru;$a.ExitCode

add -WindowStyle Hidden for invisible batch.