Tired of wading throug MMC jungles, I need a way to import a given .cer file (which contains just a public key) into machine-wide certificate store (don't know how is it called in English since I'm using a localized version of Windows) into "Personal Certificates" folder. Both cmd.exe or PowerShell versions will be fine.
Asked
Active
Viewed 1.0k times
5
Anton Gogolev
- 1,602
3 Answers
4
Powershell solution, using System.Security.Cryptograpy.X509Certificates:
$filename = "MyFileName.cer"
[Reflection.Assembly]::Load("System.Security, Version=2.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a")
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($filename)
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store([System.Security.Cryptography.X509Certificates.StoreName]::My,[System.Security.Cryptography.X509Certificates.StoreLocation]::LocalMachine)
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite);
$store.Add($cert);
Sorry for all the full namespace specifications, but there's no "using" directive in PowerShell.
Massimo
- 72,827
1
I don't know how to import it from the command line, but you don't need MMCs in order to install a certificate, double-clicking on it is just enough.
Massimo
- 72,827
0
This is wrong. See Massimo's post with the powershell reflection assembly.
Uh ... the powershell way is to open the MMC. Technet Link
This command opens the Certificates MMC snap-in to manage the specified certificate.
invoke item cert:\CurrentUser\my\6B8223358119BB08840DEE50FD8AF9EA776CE66B
Joseph Kern
- 9,989