2012-01-11 53 views
5
我使用 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

回答

2

聽起來像您需要驗證腳本是否已正確簽名,並且您在正確的證書存儲區中安裝了正確的證書。

使用Get-AuthenticodeSignature cmdlet可以獲取有關簽名腳本的信息。

也審查Scott's guide簽署證書。

+2

證書應該專門放在受信任的發佈者容器中 – 2012-01-11 18:39:40

6

如何在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