如何信任证书在Windows PowerShell

问题描述:

我使用 Windows 7

,并希望从Powershell运行签名脚本,PowerShell的的security-settings设置为"all-signed",和我的脚本与我公司签订valid certificate。我还将.pfx-file添加到我的本地证书商店(right-clicked the pfx-file and installed)如何信任证书在Windows PowerShell

然而,当我开始签署的脚本,我得到一个消息,说:

"Do you want to run software from this untrusted publisher? 
File Z:\Powershell Signed Scripts\signed.ps1 is published by CN=[MyCompanyName] and is not trusted on your system. Only run scripts from 
trusted publishers. 
[V] Never run [D] Do not run [R] Run once [A] Always run [?] Help 
(default is "D"):" 

因为我想自动调用在我的系统中的这些脚本,我想我导入的证书添加到信任在我的系统上列出,以便我第一次运行签名脚本时不会再收到消息。我怎样才能让我的证书成为值得信赖的证书?

+0

您确定发布您的开发证书的证书颁发机构的公共证书是否存在于您的证书库中? – JPBlanc 2012-01-11 13:56:13

听起来像您需要验证脚本是否已正确签名,并且您在正确的证书存储区中安装了正确的证书。

使用Get-AuthenticodeSignature cmdlet可以获取有关签名脚本的信息。

也审查Scott's guide签署证书。

+2

证书应该专门放在受信任的发布者容器中 – 2012-01-11 18:39:40

如何在Windows PowerShell的信任证书

事实上,你可以做到这一点没有任何MMC :)

首先,检查你的个人证书的命名,例如位置“电源” :

Get-ChildItem -Recurse cert:\CurrentUser\ |where {$_ -Match "Power"} | Select PSParentPath,Subject,Issuer,HasPrivateKey |ft -AutoSize 

(这应该是空的:)

gci cert:\CurrentUser\TrustedPublisher 

构建与路径证书命令:

$cert = Get-ChildItem Certificate::CurrentUser\My\ABLALAH 

下一步工作的certificate store在这里,我的两个证书存储工作:用户&计算机

$store = New-Object 
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store "TrustedPublisher","LocalMachine" 
$store.Open("ReadWrite") 
$store.Add($cert) 
$store.Close() 

检查,你应找到您的证书:

ls cert:\CurrentUser\TrustedPublisher 
+0

在您的示例中存储证书时,您使用的是“TrustedPublisher”,“LocalMachine”,它只能用管理员权限访问。在接下来的几行中,您指的是用户可访问的'CurrentUser \ TrustedPublisher'。因此,我建议将''LocalMachine'''改为'''CurrentUser'',以便它成为一个完整的工作示例。 – 2017-02-03 07:15:56