用于安装受信任发布者证书的 Powershell 脚本

mpe*_*n18 5 powershell certificate pki

我使用 powershell 应用程序部署工具包,我有一个脚本来安装一些 MSI。对于 MSI 之一,我有一个证书 ( cert.cer),我需要将其安装在每台机器的受信任发布者上。

在做了一些挖掘之后,我想出了这个:

certutil.exe -addstore TrustedPublisher cert.cer certutil.exe -addstore root cert.cer

这不起作用,没有错误,只是仍然提示我必须接受来自不受信任的发布者的安装。

Boo*_*Roo 8

以管理员身份打开 PowerShell 并运行:

Import-Certificate -FilePath cert.cer -CertStoreLocation Cert:\LocalMachine\TrustedPublisher
Run Code Online (Sandbox Code Playgroud)


pas*_*sha -1

这对我有用,

$pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2 
$certPath = read-host "Certificate Path"
$pfxPass = read-host "Password" -assecurestring
$pfx.import($certPath,$pfxPass,"Exportable,PersistKeySet") 
$store = new-object System.Security.Cryptography.X509Certificates.X509Store(
    [System.Security.Cryptography.X509Certificates.StoreName]::TrustedPublisher,
    "localmachine"
)
$store.open("MaxAllowed") 
$store.add($pfx) 
$store.close()
Run Code Online (Sandbox Code Playgroud)