[英]Import-PfxCertificate no-ops, but no error or anything
I'm trying to import a PFX file into the local certificate store. 我正在尝试将PFX文件导入本地证书存储区。 However,
Import-PfxCertificate
just does nothing at all. 但是,
Import-PfxCertificate
根本不做任何事情。 No return value, no error, nothing: 没有返回值,没有错误,没有:
I can double click on the PFX file in Explorer and import it with the same password, which works. 我可以在资源管理器中双击PFX文件并使用相同的密码导入它,这有效。 Something about the PowerShell CmdLet isn't working.
关于PowerShell CmdLet的一些东西不起作用。 I've also tried other stores, such as
Cert:\\LocalMachine\\My
and TrustedPeople
. 我也尝试了其他商店,例如
Cert:\\LocalMachine\\My
和TrustedPeople
。 Running it with -Verbose -Debug
doesn't show anything extra. 使用
-Verbose -Debug
运行它不会显示任何额外的内容。 Nothing in the Application or Security event logs either. Application或Security事件中的任何内容都没有记录。 I'm also running as an admin.
我也是一名管理员。 Ideas?
想法?
The Pfx file might have a cert chain. Pfx文件可能具有证书链。 Treating it as a collection would be a better way of handling the certificate store.
将其作为集合处理将是处理证书存储的更好方法。 See installing cert chain for the C# this was based off;
请参阅安装基于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()
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.