当前位置: 代码网 > it编程>前端脚本>Powershell > PowerShell因为在此系统中禁止执行脚本的解决方法

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

2024年05月18日 Powershell 我要评论
在powershell直接脚本时会出现:无法加载文件 ******.ps1,因为在此系统中禁止执行脚本。有关详细信息,请参阅 "get-help about_signing"。 所在位置 行:1 字符

在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:

run a vbscript file

to run a vbscript from the cmd shell:

“the method of the enterprising is to plan with audacity and execute with vigor” ~ john christian bovee

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com