从命令行将pfx文件导入特定的证书库

Bob*_*way 32 powershell certificate certutil

使用CertUtil从pfx文件导入证书到用户的个人存储中相对容易:

certutil –f –p [certificate_password] –importpfx C:\[certificate_path_and_name].pfx 
Run Code Online (Sandbox Code Playgroud)

但这最终会在当前用户的个人存储中出现.我需要在LocalMachine上的TrustedPeople中使用它.

有什么方法可以从命令行执行此操作,通过调用certutil importpfx上的不同参数,使用另一个certutil命令或其他实用程序?Powershell是另一种可能性,虽然我对此并不了解.

干杯,马特

jas*_*ard 58

将我的发现寄托在未来的读者身上.

将证书导入本地计算机上的受信任的根证书颁发机构:

CERTUTIL -addstore -enterprise -f -v root "somCertificat.cer"
Run Code Online (Sandbox Code Playgroud)

在本地计算机上将pfx导入Personal

CERTUTIL -f -p somePassword -importpfx "somePfx.pfx"
Run Code Online (Sandbox Code Playgroud)

将pfx导入本地计算机上的受信任人 - 链接到importpfx.exe

importpfx.exe -f "somePfx.pfx" -p "somePassword" -t MACHINE -s "TRUSTEDPEOPLE"
Run Code Online (Sandbox Code Playgroud)

将证书导入本地计算机上的受信任人员

Certutil -addstore -f "TRUSTEDPEOPLE" "someCertificate.cer"
Run Code Online (Sandbox Code Playgroud)


mao*_*o47 7

对于其他寻找此问题的人,我无法使用certutil -importpfx到特定的商店,我不想下载jaspernygaard的答案提供的importpfx工具,以避免将文件复制到大量服务器的要求.我最终在这里显示的PowerShell脚本中找到了答案.

该代码用于System.Security.Cryptography.X509Certificates导入证书,然后将其移动到所需的存储中:

function Import-PfxCertificate { 

    param([String]$certPath,[String]$certRootStore = “localmachine”,[String]$certStore = “My”,$pfxPass = $null) 
    $pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2 

    if ($pfxPass -eq $null) 
    {
        $pfxPass = read-host "Password" -assecurestring
    } 

    $pfx.import($certPath,$pfxPass,"Exportable,PersistKeySet") 

    $store = new-object System.Security.Cryptography.X509Certificates.X509Store($certStore,$certRootStore) 
    $store.open("MaxAllowed") 
    $store.add($pfx) 
    $store.close() 
}
Run Code Online (Sandbox Code Playgroud)


rav*_*nth 6

请查看以下链接:http: //www.orcsweb.com/blog/james/powershell-ing-on-windows-server-how-to-import-certificates-using-powershell/

进口证书:http://poshcode.org/1937

你可以这样做:

dir -Path C:\Certs -Filter *.cer | Import-Certificate -CertFile $_ -StoreNames AuthRoot, Root -LocalMachine -Verbose
Run Code Online (Sandbox Code Playgroud)


小智 5

对于 Windows 10:

将证书导入到当前用户的受信任根证书颁发机构:

certutil -f -user -p certPassword -importpfx root "example.pfx"
Run Code Online (Sandbox Code Playgroud)

将证书导入到当前用户的受信任人员:

certutil -f -user -p certPassword -importpfx TrustedPeople "example.pfx"
Run Code Online (Sandbox Code Playgroud)

将证书导入到本地计算机上的受信任根证书颁发机构:

certutil -f -user -p certPassword -enterprise -importpfx root "example.pfx"
Run Code Online (Sandbox Code Playgroud)

将证书导入到本地计算机上的受信任人员:

certutil -f -user -p certPassword -enterprise -importpfx TrustedPeople "example.pfx"
Run Code Online (Sandbox Code Playgroud)