首页 > 解决方案 > 使用 power shell 脚本将证书导入证书存储不起作用但手动工作

问题描述

我正在创建 SSL 证书以绑定到我的网站。我正在使用 power shell 脚本来自动化我从创建到将证书导入证书存储的过程。一旦我将证书绑定到我的网站,我的网站就无法工作。但是如果我手动将证书导入证书存储并将其绑定到我的网站。我没有遇到任何问题。

我正在调用一个脚本,它将根证书添加到受信任的根,并将客户端证书添加到个人存储。

$pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2 
$rootCertImportPath = $runtimeDirPath + $rootCertName
$pfx.import($rootCertImportPath,$rootCAPass,"Exportable,PersistKeySet") 

$store = new-object System.Security.Cryptography.X509Certificates.X509Store(
    [System.Security.Cryptography.X509Certificates.StoreName]::Root,
    "localmachine"
)
$store.open("MaxAllowed") 
$store.add($pfx) 
$store.close()

我正在尝试使用 $pfx.import 调用导入 .cer 文件扩展名。我需要将其他参数传递给下面提到的函数吗?

$pfx.import($rootCertImportPath,$rootCAPass,"Exportable,PersistKeySet")

请帮帮我!

标签: powershellx509certificate

解决方案


您没有导入 PFX,您只导入了没有私钥的公共证书。所以正确的调用是:

$pfx.import($rootCertImportPath)

没有使用其他参数。


推荐阅读