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  [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不会被删除.

PowerShell: 如何解决File **.ps1 cannot be loaded because the execution of scripts is disabled on this sy的更多相关文章

  1. PS1--cannot be loaded because the execution of scripts is disabled on this system

    在nagiosXI上,通过nsclient++ 引用plugin “check_ms_win_disk_load”(https://outsideit.net/check-ms-win-disk-lo ...

  2. PowerShell “execution of scripts is disabled on this system.”

    Set-ExecutionPolicy RemoteSigned

  3. Powershell profile.ps1 cannot be loaded because its operation is blocked by software restriction policies

    Powershell profile.ps1 cannot be loaded because its operation is blocked by software restriction pol ...

  4. jquery解决file上传图片+图片预览

    js解决file上传图片+图片预览 demo案例中代码为js原生控制,可以根据项目的需求修改为jquery操作 <!DOCTYPE html><html lang="en& ...

  5. Powershell cannot be loaded because running scripts is disabled on this system 解决办法

    问题背景 第一次跑ps时,出现了下面的提示.这是因为windows不允许执行脚本而已,不要大惊小怪. 解决办法 这个需要管理员执行,不然会出现以下的情况 正常情况

  6. ng : File C:\Users\baron\AppData\Roaming\npm\ng.ps1 cannot be loaded because running

    一. Windos PowerShell 选择 管理员身份运行二.set-ExecutionPolicy RemoteSigned 然后更改权限为A 三.get-ExecutionPolicy 查看当 ...

  7. SharePoint 2007 Full Text Searching PowerShell and CS file content with SharePoint Search

    1. Ensure your site or shared folder in one Content Source. 2. Add file types. 3. The second step in ...

  8. 解决File.delete()删除不掉文件

    首先注意两点: 此文件被使用的时候无法删除(比如网络输出没关闭流) 判断此文件是否存在再做删除(exists) 删除文件夹之前先删除文件夹下的所有文件(递归解决) 判断是否删除成功会有返回值,文件名错 ...

  9. 分享我编写的powershell脚本:ssh-copy-id.ps1

      问:通过[字符串界面].如何从win,通过ssh,连接到sshd?答:在任意版本win中,通过cmd.exe,powershell.exe中调用ssh.exe,连接sshd.   问:通过[pow ...

随机推荐

  1. -_-#URL区分大小写吗

    Should url be case sensitive?

  2. python学习笔记(集合的使用)

    集合 集合(set):把不同的元素组成一起形成集合,是python基本的数据类型. 集合元素(set elements):组成集合的成员 为什么需要集合? 集合的作用 1 .列表去重复数据 按照现有知 ...

  3. 坑爹火狐浏览器会记录表单数据,导致服务器控件点击事件出bug

    解决方案:在form表单加入 autocomplete="off".

  4. WebView redirect https to http

    最新项目大改版,刚好对相关sdk版本做了下升级,target也从19升级到21. 意外发现原先在WebView中加载的网页中的图片全都变得一片白,连默认图片都不给显示. 经过一番测试才发现是由于tar ...

  5. Demon_打砖块(建造一面墙,发射子弹打砖块)

    using UnityEngine; using System.Collections; public class CubeInit : MonoBehaviour { //砖块预设体 public ...

  6. JStorm 是一个分布式实时计算引擎

    alibaba/jstorm JStorm 是一个分布式实时计算引擎. JStorm 是一个类似Hadoop MapReduce的系统, 用户按照指定的接口实现一个任务,然后将这个任务递交给JStor ...

  7. [Redux] Introduction

    Single immutable state tree: Should be just one single javascript object. Describing the changes by ...

  8. mysql将一个库中表的某几个字段插入到另一个库中的表

    insert into dbname1.tablename1(filed1,filed2,filed3) select filed1,filed2,filed3from dbname2.tablena ...

  9. 面试题 HashMap 数据结构 实现原理

    数据结构 HashMap的数据结构 数据结构中有数组和链表来实现对数据的存储,但这两者基本上是两个极端. 数组:数组存储区间是连续的,占用内存严重,故空间复杂的很大.但数组的二分查找时间复杂度小,为O ...

  10. Node.js脚本杀掉占用端口的进程

    express默认端口为3000,由于实际需要改为3392,修改监听3392之后,没有成功,发现该端口被系统正占用,为了避免每次都手工停掉该系统调用,释放端口,故写了如下脚本. var cmd=pro ...