windows 如何摆脱 Batch/Powershell 中的安全警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14817141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:15:53  来源:igfitidea点击:

How to get rid of security warning in Batch/Powershell

windowssecuritypowershellbatch-fileexecution

提问by Darktux

enter image description hereI am trying to execute a powershell script via batch file and constantly getting the following warning;

在此处输入图片说明我正在尝试通过批处理文件执行 powershell 脚本并不断收到以下警告;

-> the execution policy is set to remote signed ; i also tested with Unrestricted, the same error shows up; how to get rid of this?

-> 执行策略设置为远程签名;我也用 Unrestricted 进行了测试,出现了同样的错误;如何摆脱这个?

回答by Lo?c MICHEL

Is your ps1 script reside in a network share ? You can skip all the security process by typing set-executionpolicy bypassin a admin powershell console

您的 ps1 脚本是否位于网络共享中?您可以通过set-executionpolicy bypass在管理 powershell 控制台中键入来跳过所有安全过程

or you can invoke your script by powershell.exe -executionpolicy bypass -file \\servername\share\script.ps1

或者您可以通过调用您的脚本 powershell.exe -executionpolicy bypass -file \\servername\share\script.ps1

回答by mjolinor

If the same error shows up, make sure you're setting the execution policy in the right place. On a 64 bit system there will be an execution policy for both 64 and 32 bit versions of Powershell. Normally, it loads the 64 bit version for the console, but uses the 32 bit version if called from a bat file. You need to launch the 32 bit version, running eleveated, and set the execution policy for it also.

如果出现相同的错误,请确保在正确的位置设置执行策略。在 64 位系统上,将有针对 64 位和 32 位版本的 Powershell 的执行策略。通常,它为控制台加载 64 位版本,但如果从 bat 文件调用,则使用 32 位版本。您需要启动 32 位版本,运行 eleveated,并为其设置执行策略。