错误提示

无法加载文件 D:\test.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
+ CategoryInfo : SecurityError: (:) [],ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnauthorizedAccess

解决方法

1、查看策略

PS C:\Users\Administrator> get-executionpolicy

# 默认
Restricted

2、设置

PS C:\Users\Administrator> set-executionpolicy remotesigned

3、输入 "Y" 确认

执行策略更改
执行策略可帮助你防止执行不信任的脚本。更改执行策略可能会产生安全风险,如 https:/go.microsoft.com/fwlink/?LinkID=135170
中的 about_Execution_Policies 帮助主题所述。是否要更改执行策略?
[Y] 是(Y) [A] 全是(A) [N] 否(N) [L] 全否(L) [S] 暂停(S) [?] 帮助 (默认值为“N”): Y

4、再次查看

PS C:\Users\Administrator> get-executionpolicy

# 输出
RemoteSigned