简体   繁体   English

Import-PfxCertificate no-ops,但没有错误或任何内容

[英]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\\MyTrustedPeople 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.

相关问题 Import-PfxCertificate没有提示? - Import-PfxCertificate without prompt? 导入 PfxCertificate 返回 FileNotFoundException - Import-PfxCertificate returns FileNotFoundException Import-PFXCertificate密码问题 - Import-PFXCertificate password issue Import-PFXCertificate:指定的网络密码不正确 - Import-PFXCertificate: The specified network password is not correct 导入带有“Import-PfxCertificate”的证书会导致证书无效 - Importing a certificate with "Import-PfxCertificate" results in an invalid cert 通过 Import-PFXCertificate 导入 PFX 时没有私钥? - No Private Key when importing PFX via Import-PFXCertificate? Import-PfxCertificate 未将证书保存在指定的系统存储位置 - Import-PfxCertificate not saving certificate in designated System Store Location Import-PfxCertificate Powershell功能在Localmachine上运行正常,但在其他虚拟机上使用Powershell远程处理时不起作用 - Import-PfxCertificate powershell function work fine on Localmachine but not working when using powershell remoting on other virtual machine 在 powershell 中使用 Import-PfxCertificate 命令安装证书 pfx 文件时找不到私钥 - private key not found while certificate pfx file installed with Import-PfxCertificate command in powershell 带有foreach方案的Export-PfxCertificate - Export-PfxCertificate with foreach scenario
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM