File C:\Temp\Test.ps1 cannot be loaded because the execution of scripts is disabledon this system.

PowerShell 默认不允许执行*.ps1脚本文件。运行ps1文件会得到下面的错误:

File C:\Temp\Test.ps1 cannot be loaded because the execution of scripts is disabledon this system. Please see "get- help about_signing" for moredetails.

At line:1char:19
+ c:\Temp\Test.ps1 <<<<

 

可以通过Get-ExecutionPolicy,来取得当前策略。

用Set-ExecutionPolicy设置当前策略。

 

下面的命令可以解决上面的错误

PS C:\Windows\system32> Set-ExecutionPolicy RemoteSigned <按回车>

ExecutionPolicy Change

Theexecution policy helps protect you from scripts that you do not trust. Changingthe execution policy might expose 

you tothe security risks described in the about_Execution_Policies help topic. Do youwant to change the execution

policy?

[Y] Yes [N] No  [S] Suspend  [?] Help (default is "Y"):<Y>

 

 在PowerShell中的执行

 

 

Policy的有效参数:

-- Restricted: 不载入任何配置文件,不运行任何脚本。 "Restricted" 是默认的。

--AllSigned: 只有被Trusted publisher签名的脚本或者配置文件才能使用,包括你自己再本地写的脚本

--RemoteSigned:  对于从Internet上下载的脚本或者配置文件,只有被Trusted publisher签名的才能使用。

--Unrestricted: 可以载入所有配置文件,可以运行所有脚本文件. 如果你运行一个从internet下载并且没有签名的脚本,在运行之前,你会被提示需要一定的权限。

--Bypass: 所有东西都可以使用,并且没有提示和警告.

-- Undefined: 删除当前scope被赋予的Execution Policy.  但是Group Policy scope的Execution Policy不会被删除.

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值