Powershell 无法将windows证书导出为pkcs12-“;密钥在指定状态下无效;
我正在尝试使用powershell将证书导出到pkcs12。我可以在MMC中很好地导出它。但powershell会呕吐Powershell 无法将windows证书导出为pkcs12-“;密钥在指定状态下无效;,powershell,pkcs#12,Powershell,Pkcs#12,我正在尝试使用powershell将证书导出到pkcs12。我可以在MMC中很好地导出它。但powershell会呕吐 PS C:\Users\paul> $cert.export('PFX'," pass") Exception calling "Export" with "2" argument(s): "Key not valid for use in specified state. " At line:1 char:13 + $cert.export <<&l
PS C:\Users\paul> $cert.export('PFX'," pass")
Exception calling "Export" with "2" argument(s): "Key not valid for use in specified state.
"
At line:1 char:13
+ $cert.export <<<< ('PFX'," pass")
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
以本地管理员身份运行这似乎是一个不太可能的选择,但是您是否尝试过使用Pfx枚举而不是字符串
$pfx = [System.Security.Cryptography.X509Certificates.X509ContentType]::Pfx
$cert.Export($pfx,"pass")
我问这个问题的原因是,如果你看一下枚举背后的值,Pfx实际上有一个值3。不知什么原因,当我清理完所有内容并重新开始时,它就开始工作了——软件的奥秘!
$pfx = [System.Security.Cryptography.X509Certificates.X509ContentType]::Pfx
$cert.Export($pfx,"pass")