簡體   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