powershell导入脚本失败,禁止运行脚本,无法远程连接服务器

报错:

Import-Module : 无法加载文件 C:\Users\t\Desktop\nishang-master\nishang.psm1,因为在此系统上禁止运行脚本。有关详细
信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 1
+ Import-Module .\nishang.psm1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [Import-Module],PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand

以管理员身份运行powershell
查询计算机上的现用执行策略

get-executionpolicy
Restricted

解决:(执行策略更改为 RemoteSigned)

set-executionpolicy Unrestricted

导入脚本后
查看模块命令Get-Command -Module nishang
出现模块即导入成功

一般来说powershell导入脚本失败的原因是powershell策略的问题

查看当前系统powershell的执行策略:
Get-ExecutionPolicy
若要获取影响当前会话的所有执行策略:
Get-ExecutionPolicy -List
设置策略是
Set-ExecutionPolicy 策略名
设置某个特定作用域中的执行策略
set-executionpolicy 策略名 -Scope CurrentUser
具体策略有:.
Unrestricted:允许所有的脚本执行。 —危险Restricted:脚本不能运行;
RemoteSigned:本地创建的脚本可以执行,但是网上下载的不允许;.
AllSigned:脚本有受信任的发布者签名时才能执行;u
Bypass:绕过安全策略执行脚本
AllSigned 和 RemoteSigned 执行策略可防止 Windows PowerShell 运行没有数字签名的脚本。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值