Pages

Wednesday, September 07, 2011

Export Certificates using Powershell

dir cert:\LocalMachine\My | Where-Object { $_.hasPrivateKey } | Foreach-Object { [system.IO.file]::WriteAllBytes("$home\$($_.SubjectName).pfx", ($_.Export('PFX', '')) ) }

2 comments:

  1. when running this script I get an error on the Export section:
    Exception calling "Export" with "2" argument(s): "Key not valid for use in specified state.

    ReplyDelete
  2. Maybe your certificate does not have exportable private key.

    ReplyDelete