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', '')) ) }


Craig said...

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.

Mijalko said...

Maybe your certificate does not have exportable private key.