从Windows命令行导入.cer证书

厌倦了通过MMC丛林涉水,我需要一种方法来导入一个给定的.cer文件(其中只包含一个公钥)到机器范围的证书存储(不知道如何在英语中调用,因为我使用本地化Windows的版本)到“个人证书”文件夹中。 cmd.exe或PowerShell版本都可以。

Powershell解决scheme,使用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); 

很抱歉,所有完整的命名空间规范,但在PowerShell中没有“使用”指令。

我不知道如何从命令行导入它,但是您不需要MMC来安装证书,双击它就足够了。

这是错误的。 请参阅Massimo的post与powershellreflection大会。


呃… powershell的方法是打开MMC。 Technet链接

此命令将打开“证书”MMCpipe理单元以pipe理指定的证书。

 invoke item cert:\CurrentUser\my\6B8223358119BB08840DEE50FD8AF9EA776CE66B