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 關注
- 3441 瀏覽
添加回答
舉報