PowerShell执行策略是Windows系统的一项安全功能,用于控制脚本的运行权限级别。它决定了哪些脚本可以运行,以及是否需要数字签名验证。默认情况下,Windows系统设置为"Restricted"(限制)策略,这会阻止所有脚本运行。
要查看当前PowerShell执行策略,请以管理员身份打开PowerShell并输入:
Get-ExecutionPolicy
系统将返回当前策略级别,常见的有:
Set-ExecutionPolicy RemoteSigned -Scope Process
Set-ExecutionPolicy RemoteSigned
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
如果收到"拒绝访问"错误,请确保:
尝试刷新策略:
gpupdate /force
powershell.exe -ExecutionPolicy Bypass -File script.ps1