Difference between revisions of "Powershell get certificates"

From UVOO Tech Wiki
Jump to navigation Jump to search
(Created page with " ``` $store = New-Object System.Security.Cryptography.X509Certificates.X509Store([System.Security.Cryptography.X509Certificates.StoreName]::My,"localmachine") $store.Open("Max...")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
```
 +
$mypwd = ConvertTo-SecureString -String 'changeme' -Force -AsPlainText
 +
gci -path cert:\localmachine\My\${THUMBPRINT} | Export-PfxCertificate -FilePath user.pfx -Password $mypwd
 +
or
 +
| Export-Certificate -Cert $cert -FilePath user.cer
 +
```
  
 
```
 
```
Line 7: Line 13:
 
$store.Close()
 
$store.Close()
 
```
 
```
 +
 +
Make key exportable if you want to get private key
 +
 +
https://stackoverflow.com/questions/63129907/how-to-request-a-exportable-certificate-using-powershell
 +
 +
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/certreq_1
 +
 +
https://learn.microsoft.com/en-us/answers/questions/446749/export-certificate-wth-private-key

Latest revision as of 18:22, 21 September 2023

$mypwd = ConvertTo-SecureString -String 'changeme' -Force -AsPlainText
gci -path cert:\localmachine\My\${THUMBPRINT} | Export-PfxCertificate -FilePath user.pfx -Password $mypwd
or
| Export-Certificate -Cert $cert -FilePath user.cer
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store([System.Security.Cryptography.X509Certificates.StoreName]::My,"localmachine")
$store.Open("MaxAllowed")
$cert = $store.Certificates | ?{$_.subject -match "^CN=asdasd"}
$cert.PrivateKey.ToXmlString($false)
$store.Close()

Make key exportable if you want to get private key

https://stackoverflow.com/questions/63129907/how-to-request-a-exportable-certificate-using-powershell

https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/certreq_1

https://learn.microsoft.com/en-us/answers/questions/446749/export-certificate-wth-private-key