报错:
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 运行没有数字签名的脚本。