Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 4 down vote accepted

Powershell solution, using System.Security.Cryptograpy.X509Certificates:

$filename = "MyFileName.cer"

[Reflection.Assembly]::Load("System.Security, Version=, 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)



Sorry for all the full namespace specifications, but there's no "using" directive in PowerShell.

share|improve this answer
It's all those pesky reflection.Assemblies that I need to learn ... Will be stealing this for later use. – Joseph Kern Oct 15 '09 at 11:27
last line of the script misses '$' in front of cert: $store.Add($cert); – Andrey Nov 6 '13 at 4:56

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.

share|improve this answer

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
share|improve this answer
How does this relate to importing a .cer file, exactly? – Massimo Oct 14 '09 at 14:15
This is to say, you can't import a cert from powershell, you need to use the mmc. The mmc can be invoked from powershell. I've been down-voted twice, but no one has posted anything to the contrary. – Joseph Kern Oct 14 '09 at 17:02
You've been downvoted because you posted something quite unrelated to the question asked... – Massimo Oct 15 '09 at 8:23
BTW, your answer is actually incorrect, because in PowerShell you have access to the full .NET framework, and System.Security.Cryptograpy.X509Certificates has all you need. – Massimo Oct 15 '09 at 9:24
Lol, fair enough. I see you've posted the REAL answer. Thanks! – Joseph Kern Oct 15 '09 at 11:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.