3 回答

TA貢獻(xiàn)1818條經(jīng)驗 獲得超8個贊
您需要-ExecutionPolicy參數(shù):
Powershell.exe -executionpolicy remotesigned -File C:\Users\SE\Desktop\ps.ps1
否則,PowerShell 會將參數(shù)視為要執(zhí)行的行,盡管Set-ExecutionPolicy 它是cmdlet,但沒有-File參數(shù)。

TA貢獻(xiàn)1898條經(jīng)驗 獲得超8個贊
我在這里的博客文章中解釋了為什么要從批處理文件調(diào)用PowerShell腳本以及如何執(zhí)行該腳本。
這基本上就是您要尋找的:
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腳本的整個路徑。
添加回答
舉報