#javascript
PowerShell 的执行策略(Execution Policy) 会限制了脚本的运行。 如果要修改的话,是需要管理员运行,去设置
![[Pasted image 20250529182632.png]]
运行以下命令,将执行策略设为 RemoteSigned(允许本地脚本运行):
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
如果提示是否确认更改,输入 Y 并回车。
![[Pasted image 20250529183103.png]]
修改后,如果要修改回,默认的禁用配置:
运行以下命令,将执行策略重置为 Restricted(禁止所有脚本运行):
Set-ExecutionPolicy Restricted -Scope CurrentUser
需要 管理员权限(以管理员身份运行 PowerShell)。
输入 Y 确认更改。
如果希望当前用户的策略继承系统默认(通常是 Restricted),可以设置为 Undefined:
Set-ExecutionPolicy Undefined -Scope CurrentUser
如果想查看当前生效的执行策略,运行:
Get-ExecutionPolicy -List
输出示例:
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser RemoteSigned
LocalMachine Undefined
![[Pasted image 20250529183003.png]]