首页 > 解决方案 > 从批处理文件调用 Powershell 脚本并在失败时终止

问题描述

我正在尝试在批处理文件中调用 Powershell 脚本

例如。

测试.ps1

function func1(){
#Do something
}

function func2(){
#Do something
}

func1()
func2()

批处理脚本

:: Do something

PowerShell.exe -Command "& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy Bypass -File ""test.ps1""' -Verb RunAs}"

:: Exit execution if powershell execution failed.

如果 powershell 执行遇到任何问题,如何终止批处理文件的执行。

标签: powershellbatch-file

解决方案


推荐阅读