PowerShell因为在此系统中禁止执行脚本的解决方法

所属分类: 脚本专栏 / PowerShell 阅读数: 1761
收藏 0 赞 0 分享

在Powershell直接脚本时会出现:

无法加载文件 ******.ps1,因为在此系统中禁止执行脚本。有关详细信息,请参阅 "get-help about_signing"。
所在位置 行:1 字符: 17
+ E:\Test\test.ps1 <<<<
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException

ps1的内容:

在powershell中执行 set-ExecutionPolicy RemoteSigned

下图可以看到原来是无法运行对的,执行了上面的命令后就可以了,如下图

查看“get-help about_signing”:

主题
about_signing

简短说明
说明如何对脚本进行签名以使其符合 Windows PowerShell 执行策略。

详细说明
Restricted 执行策略不允许任何脚本运行。
AllSigned 和 RemoteSigned 执行策略可防止 Windows PowerShell 运行没有数字签名的脚本。

本主题说明如何运行所选未签名脚本(即使在执行策略为 RemoteSigned 的情况下),还说明如何对
脚本进行签名以便您自己使用。

有关 Windows PowerShell 执行策略的详细信息,请参阅 about_Execution_Policy。

允许运行签名脚本
-------------------------------
首次在计算机上启动 Windows PowerShell 时,现用执行策略很可能是 Restricted(默认设置)。

Restricted 策略不允许任何脚本运行。

若要了解计算机上的现用执行策略,请键入:

get-executionpolicy

若要在本地计算机上运行您编写的未签名脚本和来自其他用户的签名脚本,请使用以下命令将计算机上的
执行策略更改为 RemoteSigned:

set-executionpolicy remotesigned

有关详细信息,请参阅 Set-ExecutionPolicy。

执行“set-ExecutionPolicy RemoteSigned ”:

执行策略更改
执行策略可以防止您执行不信任的脚本。更改执行策略可能会使您面临 about_Execution_Policies
帮助主题中所述的安全风险。是否要更改执行策略?
[Y] 是(Y) [N] 否(N) [S] 挂起(S) [?] 帮助 (默认值为“Y”): y

Run a CMD batch file

To run a batch script from the CMD shell, save the file as plain ASCII text with the file extension .CMD, then from the command line, enter the name of the script and press return.

C:\Batch> Demo.cmd

To run a batch file from within another batch file, use the CALL command, otherwise the first script will exit without performing any further commands.

It is also possible to run batch scripts with the old (Windows 95 style) .BAT extension, but be aware that these will set ERRORLEVEL differently.

Run a Powershell script
To run a PowerShell script from the CMD shell:

复制代码 代码如下:

C:\> powershell -file "c:\batch\demo.ps1"

Run a VBScript file

To run a VBScript from the CMD shell:

复制代码 代码如下:

C:\> cscript c:\batch\demo.vbs

“The method of the enterprising is to plan with audacity and execute with vigor” ~ John Christian Bovee

更多精彩内容其他人还在看

Powershell学习笔记--使用正则表达式查找文件

本文介绍PowerShell中使用正则表达式的查找文件的方法,PowerShell的正则表达式与微软其它语言的正则表达式是一样的,使用非常方便。
收藏 0 赞 0 分享

Windows Powershell 介绍和安装

Powershell 是运行在windows机器上实现系统和应用程序管理自动化的命令行脚本环境。微软之所以将Powershell 定位为Power,并不是夸大其词,因为它完全支持对象。其可读性,易用性,可以位居当前所有shell之首。
收藏 0 赞 0 分享

Windows Powershell 自定义控制台

这篇文章主要介绍了Windows Powershell 自定义控制台,包括选项、字体、布局和颜色四个方面的自定义风格,希望对大家有所帮助
收藏 0 赞 0 分享

windows Powershell 快速编辑模式和标准模式

powershell控制台有两种模式,一个是快速编辑模式,一个是标准模式。
收藏 0 赞 0 分享

PowerShell中查找字符串位置的IndexOf函数使用实例

这篇文章主要介绍了PowerShell中查找字符串位置的IndexOf函数使用实例,例子简单明了,容易看懂,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell使用正则表达式查找字符串实例

这篇文章主要介绍了PowerShell使用正则表达式查找字符串实例,主要是对match运算符的使用介绍,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell中使用正则表达式跨行匹配字符串的方法

这篇文章主要介绍了PowerShell中使用正则表达式跨行匹配字符串的方法,重点在于正则表达式的写法,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell中查看当前版本、Windows版本、.NET版本信息的代码

这篇文章主要介绍了PowerShell中查看当前版本、Windows版本、.NET版本信息的代码,需要的朋友可以参考下
收藏 0 赞 0 分享

PowerShell 入门基础教程

Windows PowerShell 是专为系统管理员设计的新 Windows 命令行外壳程序。该外壳程序包括交互式提示和脚本环境,两者既可以独立使用也可以组合使用
收藏 0 赞 0 分享

PowerShell Contains函数查找字符串实例

这篇文章主要介绍了PowerShell Contains函数查找字符串实例,Contains函数的作用是查询一个字符串中是否存在另一个字符串,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多