为什么我的powershell脚本不能运行?
我写了一个简单的批处理文件作为PowerShell脚本,并且在运行时遇到错误。
它位于我的路径中的脚本目录中。
Cannot be loaded because the execution of scripts is disabled on this system.
please see "get-help about-signing".
我看着帮助,但它不是帮助。
可能是PowerShell的默认安全级别,(IIRC)只能运行签名脚本。
尝试输入此内容:
set-executionpolicy remotesigned
这将告诉PowerShell允许本地(即在本地驱动器上)未签名的脚本运行。
然后再次尝试执行脚本。
你需要运行set-executionpolicy:
Set-ExecutionPolicy Restricted <-- Will not allow any powershell scripts to run. Only individual commands may be run.
Set-ExecutionPolicy AllSigned <-- Will allow signed powershell scripts to run.
Set-ExecutionPolicy RemoteSigned <-- Allows unsigned local script and signed remote powershell scripts to run.
Set-ExecutionPolicy Unrestricted <-- Will allow unsigned powershell scripts to run. Warns before running downloaded scripts.
Set-ExecutionPolicy Bypass <-- Nothing is blocked and there are no warnings or prompts.
希望这可以帮助!
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
始终使用上面的cmd
来启用在当前会话中执行powershell。