AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 685812
Accepted
Phil
Phil
Asked: 2015-04-28 02:12:45 +0800 CST2015-04-28 02:12:45 +0800 CST 2015-04-28 02:12:45 +0800 CST

Powershell 将证书传输到新 PC - 如何确定证书是否可导出

  • 772

我正在使用以下 powershell 获取证书列表,包括任何已归档的证书,以便我可以轻松地将它们传输到新 PC

$store=new-object 
System.Security.Cryptography.X509Certificates.X509Store("My","CurrentUser")
$store.open("ReadOnly,IncludeArchived")
$privateCerts = $store.Certificates | Where-Object { $_.hasPrivateKey }

但是,当我尝试使用例如将它们导出到 pfx 文件时

$privateCerts| Foreach-Object { [system.IO.file]::WriteAllBytes("$($_.thumbprint)$($_.Subject).pfx", ($_.Export('PFX', 'password')) ) }

它会为任何不可导出的异常抛出异常。现在我知道我无法导出这些,但我想跳过它们而不让脚本抛出错误。我可以通过捕获异常来解决它,但是有没有办法确定证书是否可导出。

我找到了对 x509keystorageflags 的引用,它有一个我可以检查的“可导出”位,但我无法弄清楚如何使用 powershell 获取证书的信息。

powershell
  • 1 1 个回答
  • 849 Views

1 个回答

  • Voted
  1. Best Answer
    Mathias R. Jessen
    2015-04-28T03:09:07+08:002015-04-28T03:09:07+08:00

    该Exportable位是在私钥容器本身上设置的,而不是直接在证书上:

    $privateCerts = $store.Certificates | Where-Object {$_.HasPrivateKey}
    $Exportables  = $privateCerts | Where-Object {$_.PrivateKey.CspKeyContainerInfo.Exportable}
    

    我认为这不适用于除基于 RSA 的密钥对之外的其他类型

    • 1

相关问题

  • 资源锁和电源外壳

  • 脚本 - 如何断开远程桌面会话?

  • 如何限制向通讯组发送到外部地址?

  • Powershell对值与数组的作用不同?

  • Windows Powershell Vim 键绑定

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve