将批处理脚本调用到Powershell脚本中

时间:2020-04-17 18:25:04

标签: powershell powershell-2.0 powershell-3.0 powershell-4.0

我有一个简单的批处理.bat脚本,该脚本将数据从一个位置复制到另一位置,并且批处理脚本没有任何退出代码。它只是一个带有复制命令的.bat文件,用于复制文件。我想将.bat脚本调用为Power Shell脚本,如果.bat失败,则将Power Shell脚本失败。这是我的Power Shell脚本示例代码。

$BatchScriptLocation="\\SomeNetworkServer\Folder"
$BatchScriptName="Test.bat"   ---simple batch script with no exit codes.

$RunBat = Start-Process -FilePath $BatchScriptLocation\$BatchScriptName -Wait -passthru;$a.ExitCode

If ($RunBat -eq 0) 
{
echo "Batch script execution success"
exit 0
}
else
{
echo "Batch script execution failed"
exit 1
}

0 个答案:

没有答案