I have a known-good PFX file, with the correct password. I can import it using the windows certificate UI, or the import-pfxcertificate cmdlet. However, get-pfxcertificate fails. Any ideas?
PS > $password = read-host -AsSecureString
****************
PS > Import-PfxCertificate C:\Users\mfinnigan\Desktop\test.pfx -Password $password cert:\CurrentUser\my
PSParentPath: Microsoft.PowerShell.Security\Certificate::CurrentUser\my
Thumbprint Subject EnhancedKeyUsageList
---------- ------- --------------------
<snip> CN=<snip> Client Authentication
PS > get-pfxCertificate C:\Users\mfinnigan\Desktop\test.pfx -Password $password
Get-PfxCertificate: An error occurred during encode or decode operation.
OK, I found the issue. The stored value the file is base64 encoded. Interestingly,
Import-PfxCertificate
can handle that, I'm guessing it does the decoding if it needs to, whereasget-pfxcertificate
does not. It would be super fricking helpful if these behaviors were documented somewhere, so hopefully this Q&A will be important for someone else in the future.