繁体   English   中英

如何信任 Windows Powershell 中的证书

[英]How to trust a certificate in Windows Powershell

我正在使用Windows 7 ,并且想要从Powershell运行签名脚本, Powershellsecurity-settings设置为"all-signed" ,并且我的脚本使用我公司的valid certificate签名。 我还将.pfx-file添加到我的本地证书存储(right-clicked the pfx-file and installed)

但是,当我启动一个签名脚本时,我收到一条消息:

"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"):"

因为我想在我的系统上自动调用这些脚本,所以我想将我导入的证书添加到我系统上的受信任列表中,这样我第一次运行签名脚本时就不会再收到消息。 如何使我的证书成为可信证书?

如何信任 Windows Powershell 中的证书

事实上,你可以在没有任何 mmc 的情况下做到这一点 :)

首先,检查您的个人证书的位置,例如“Power”:

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

证书存储的下一步工作(我在这里处理两个证书存储:用户和计算机

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

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

ls cert:\CurrentUser\TrustedPublisher

听起来您需要验证脚本是否已正确签名以及您是否在正确的证书存储中安装了正确的证书。

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

另请查看Scott 的证书签名指南

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM