Powershell 导入PfxCertificate无操作,但无错误或任何内容
我正在尝试将PFX文件导入本地证书存储。然而,Powershell 导入PfxCertificate无操作,但无错误或任何内容,powershell,certificate,windows-server-2016,pfx,Powershell,Certificate,Windows Server 2016,Pfx,我正在尝试将PFX文件导入本地证书存储。然而,Import PfxCertificate什么也不做。无返回值、无错误、无任何内容: 我可以双击资源管理器中的PFX文件,并使用相同的密码导入它,这很有效。有关PowerShell CmdLet的某些内容不起作用。我也尝试过其他商店,比如Cert:\LocalMachine\My和TrustedPeople。使用-Verbose-Debug运行它不会显示任何额外内容。应用程序或安全事件日志中也没有任何内容。我也是一名管理员。想法?Pfx文件可能有一
Import PfxCertificate
什么也不做。无返回值、无错误、无任何内容:
我可以双击资源管理器中的PFX文件,并使用相同的密码导入它,这很有效。有关PowerShell CmdLet的某些内容不起作用。我也尝试过其他商店,比如
Cert:\LocalMachine\My
和TrustedPeople
。使用-Verbose-Debug
运行它不会显示任何额外内容。应用程序或安全事件日志中也没有任何内容。我也是一名管理员。想法?Pfx文件可能有一个证书链。将其视为集合将是处理证书存储的更好方法。参见C#这是基于
[string] $certPath = '.\test.pfx';
[string] $certPass = 'MyPassword';
# Create a collection object and populate it using the PFX file
$collection = [System.Security.Cryptography.X509Certificates.X509Certificate2Collection]::new();
$collection.Import($certPath, $certPass, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::PersistKeySet);
try {
# Open the Store My/Personal
$store = [System.Security.Cryptography.X509Certificates.X509Store]::new('My');
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite);
foreach ($cert in $collection) {
Write-Host ("Subject is: '{0}'" -f $cert.Subject )
Write-Host ("Issuer is: '{0}'" -f $cert.Issuer )
# Import the certificate into an X509Store object
# source https://support.microsoft.com/en-au/help/950090/installing-a-pfx-file-using-x509certificate-from-a-standard-net-applic
if ($cert.Thumbprint -in @($store.Certificates | % { $_.Thumbprint } )) {
Write-Warning "Certificate is already in the store"
# Force the removal of the certificate so we have no conflicts, not required if this is the first install
$store.Remove($cert)
}
# Add in the certificate
$store.Add($cert);
}
} finally {
if($store) {
# Dispose of the store once we are done
$store.Dispose()
}
}
我明白了。这是因为PFX没有私钥。似乎安装在服务结构集群上的证书是不可导出的,因此当您与Docker容器共享它们时,它们的私钥会被剥离。我也遇到了同样的问题。这是由于链中的证书存储在多个位置(副本)造成的。我导出了证书及其链,删除了所有副本,导入,然后运行脚本安装新证书。然后我得到了输出。似乎没有输出是错误的。