PowerShell: 如何解决File **.ps1 cannot be loaded because the execution of scripts is disabled on this sy
2017-10-10 21:15
926 查看
转自:http://www.cnblogs.com/findcaiyzh/archive/2012/09/21/2696282.html
PowerShell 默认不允许执行*.ps1脚本文件。运行ps1文件会得到下面的错误:
File C:\Temp\Test.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get- help about_signing" for more details.
At line:1 char:19
+ c:\Temp\Test.ps1 <<<<
可以通过Get-ExecutionPolicy,来取得当前策略。
用Set-ExecutionPolicy设置当前策略。
下面的命令可以解决上面的错误
PS C:\Windows\system32> Set-ExecutionPolicy RemoteSigned <按回车>
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic. Do you want to change the execution
policy?
[Y] Yes
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不会被删除.
PowerShell 默认不允许执行*.ps1脚本文件。运行ps1文件会得到下面的错误:
File C:\Temp\Test.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get- help about_signing" for more details.
At line:1 char:19
+ c:\Temp\Test.ps1 <<<<
可以通过Get-ExecutionPolicy,来取得当前策略。
用Set-ExecutionPolicy设置当前策略。
下面的命令可以解决上面的错误
PS C:\Windows\system32> Set-ExecutionPolicy RemoteSigned <按回车>
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic. Do you want to change the execution
policy?
[Y] Yes
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不会被删除.
相关文章推荐
- PowerShell: 如何解决File **.ps1 cannot be loaded because the execution of scripts is disabled on this sy
- PowerShell: 如何解决File **.ps1 cannot be loaded because the execution of scripts is disabled on this system.
- PowerShell: 如何解决File **.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get- help about_sig" for more de
- PS1--cannot be loaded because the execution of scripts is disabled on this system
- File xxx.ps1 cannot be loaded because the execution of scripts is disabled on this system
- File C:\Temp\Test.ps1 cannot be loaded because the execution of scripts is disabledon this system.
- “The execution of scripts is disabled on this system” … How to run your own PowerShell scripts
- windows powershell错误 because the execution of scripts is disabled on this system
- PowerShell “execution of scripts is disabled on this system.”
- eclipse中设置.abc--xyz触发提示输入时,提示This compilation unit is not on the build path of java project 异常如何解决?
- 如何解决xxx is not in the sudoers file.This incident will be reported. on Mac
- [转] EF cannot be tracked because another instance of this type with the same key is already being tracked
- One or more breakpoints cannot be set and have been disabled!Execution will stop at the beginning of the program
- 【随】Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack 问题解决。
- This action cannot be completed because the other application is busy
- SQL Server 对等复制配置失败后无法删除重建,报错:Cannot execute as the database principal because the principal "dbo" does not exist, this type of principal cannot be im
- ltib cannot be run because one or more of the host packages 解决方法参考
- This InfoPath form template is browser-compatible, but it cannot be browser-enabled on the selected site
- “System.IO.FileLoadException: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 错误
- This platform could not be created because a solution platform of the same name already exists解决方法