3 回答

TA贡献1818条经验 获得超8个赞
您需要-ExecutionPolicy参数:
Powershell.exe -executionpolicy remotesigned -File C:\Users\SE\Desktop\ps.ps1
否则,PowerShell 会将参数视为要执行的行,尽管Set-ExecutionPolicy 它是cmdlet,但没有-File参数。

TA贡献1898条经验 获得超8个赞
我在这里的博客文章中解释了为什么要从批处理文件调用PowerShell脚本以及如何执行该脚本。
这基本上就是您要寻找的:
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\Users\SE\Desktop\ps.ps1'"
如果您需要以管理员身份运行PowerShell脚本,请使用以下命令:
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""C:\Users\SE\Desktop\ps.ps1""' -Verb RunAs}"
我建议不要将批处理文件和PowerShell脚本文件放在我的博客文章中描述的相同目录中,而不是硬编码PowerShell脚本的整个路径。
- 3 回答
- 0 关注
- 3463 浏览
添加回答
举报