for /f "tokens=*" %%a in ('powershell Get-ExecutionPolicy') do (
set originPolicy=%%a
)
通过for循环查找功能来将 powershell 命令的值赋给 batch file 变量

@echo off
set dir=%CD%
set scriptPath=%dir%\example.ps1
for /f "tokens=*" %%a in ('powershell Get-ExecutionPolicy') do (
set originPolicy=%%a
)
powershell Set-ExecutionPolicy 0
powershell %scriptPath%
powershell Set-ExecutionPolicy %originPolicy%

pause

相关文章: