Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在任何服务器上运行Powershell脚本,除了获得Verisign或类似证书外,还有其他选择吗?_Powershell_Code Signing - Fatal编程技术网

在任何服务器上运行Powershell脚本,除了获得Verisign或类似证书外,还有其他选择吗?

在任何服务器上运行Powershell脚本,除了获得Verisign或类似证书外,还有其他选择吗?,powershell,code-signing,Powershell,Code Signing,我已经在编写Powershell脚本有一段时间了,它是为我个人(在我的本地计算机上)和我所在领域内外的其他人使用而设计的 问题是,当我以外的人尝试运行脚本时,他们会遇到以下错误: The file C:\my_script.ps1 cannot be loaded. The execution of scripts is disabled on this system. Please see "Get-Help about_signing" for more details. 我想我已经通过更

我已经在编写Powershell脚本有一段时间了,它是为我个人(在我的本地计算机上)和我所在领域内外的其他人使用而设计的

问题是,当我以外的人尝试运行脚本时,他们会遇到以下错误:

The file C:\my_script.ps1 cannot be loaded. The execution of scripts is disabled on this system. Please see "Get-Help about_signing" for more details.
我想我已经通过更改其他员工工作站上的策略来解决了这个问题,允许在脚本本身中进行远程签名,但是根据,我需要一些更健壮的东西


由于这个想法是允许它在内部和外部机器上独立运行,因此我不希望强制脚本将内容更改为无限制。还有其他选择吗?我是否可以用其他方式(一个人推荐了一个.NET容器)或其他方式来总结这个项目,使它运行得更干净、更独立?

我不确定我是否理解您的问题。您可以在不希望执行脚本的计算机上使用makecert:

@echo off
makecert -n "CN=PowerShell Local Certificate Root" -a sha1 -eku 1.3.6.1.5.5.7.3.3 -r -sv root.pvk root.cer -ss Root -sr LocalMachine
pause
makecert -pe -n "CN=PowerShell User" -ss MY -a sha1 -eku 1.3.6.1.5.5.7.3.3 -iv root.pvk -ic root.cer
然后,在脚本上签名:

$cert = @(Get-ChildItem cert:CurrentUser\My -codesigning)[0]
Set-AuthenticodeSignature <your script path> $cert | Out-Null
$cert=@(获取ChildItem证书:CurrentUser\My-codesigning)[0]
将Authenticode签名$cert设置为空

“自包含”部分不应该是个问题。

不要忘记将执行策略设置为AllSigned或RemoteSigned,否则它仍然不会执行脚本。所以我可以在.bat文件中放入第一位,我首先使用它来启动脚本,它将创建必要的证书并成功附加它?我承认我对证书不太熟悉,所以我不确定它是否真的会接受在脚本中创建的证书。我遇到的问题是,我需要它能够由非技术人员运行,因此我必须自动化makecert过程,但是如果我能将这一部分放入.bat文件中,其余部分放入脚本本身,那应该很好。