当前位置: 动力学知识库 > 问答 > 编程问答 >

powershell - Importing a certificate with "Import-PfxCertificate" results in an invalid cert

问题描述:

I have a certificate (.pfx) that works fine when I import it using the GUI with (include all extended properites) checked.

If I import it without that checked, I can't use it in IIS.

If I try to import it via powershell (the end goal), I also can't use it in IIS.

When I try to use it in IIS, I get this error message:

A specified logon session does not exist. It may already have been

terminated.

I've tried a few methods for importing it, this is the most recent version of my script:

$certPassword = convertto-securestring 'thecertpasswordhere' -asplaintext -force

Import-PfxCertificate $localFilePath -Password $certPassword

Does anyone have any idea how to make this work or what I can look into for more info? I've had no luck searching so far.

Thanks!

网友答案:

Verify the script is running with the appropriate credentials (i.e. LOCAL SYSTEM, etc.).

You can also try piping the certificate (*.pfx) as follows:

Get-ChildItem -Path $localFilePath | Import-PfxCertificate -CertStoreLocation Cert:\LocalMachine\My -Password (ConvertTo-SecureString -String "thecertpasswordhere"  -Force -AsPlainText
分享给朋友:
您可能感兴趣的文章:
随机阅读: