
p7b 파일에 인증서 컬렉션이 있고 인증서 템플릿에 따라 각 인증서를 올바른 저장소로 자동으로 가져오고 싶습니다. 스크립트를 사용하여 이를 수행하는 가장 좋은 방법은 무엇입니까?
를 사용해 보았는데 certutil -addstore root Certificate.p7b
모든 루트 CA가 루트 저장소에 올바르게 배치되지만 다른 유형의 인증서가 발견되면 오류가 반환됩니다.
이 작업을 수행하기 위해 배치 스크립트, vbscript 또는 powershell을 사용할 의향이 있습니다. 감사해요!
답변1
CertMgr.exe
인증서를 가져오기 위해 간단한 bat 파일을 사용합니다 .
certmgr.exe -add -c ca.cer -s -r localMachine root >> log.txt
certmgr.exe -add -c test.cer -s -r localMachine root >> log.txt
certmgr.exe -add -c edu.cer -s -r localMachine root >> log.txt
여기는TechNet 기사certmgr.exe로 수행할 수 있는 명령/사용법을 문서화한 문서
답변2
템플릿을 기반으로 인증서를 올바른 저장소로 가져오는 스크립트를 찾지 못했습니다. 나는 그 스크립트가 존재하지 않기 때문에 당신이 직접 만든 것이라고 생각합니다. 내가 찾은 것은 디렉터리에서 인증서를 가져오는 PowerShell 스크립트와 올바른 저장소를 직접 지정해야 하는 명령입니다. 나는 그것이 당신에게 유용할 것이라고 생각했습니다:
스크립트를 사용하는 방법 보안 인증서를 가져오는 기능입니다.
참고: 사용 가능한 상점 이름 목록을 얻으려면 다음 명령을 실행하십시오. dir cert: | 선택 - 매장 이름 확장
사용 예: Import-Certificate -CertFile "VeriSign_Expires-2028.08.01.cer" -StoreNames AuthRoot, Root -LocalMachine
가져오기 인증서 -CertFile "VeriSign_Expires-2018.05.18.p12" -StoreNames AuthRoot -LocalMachine -CurrentUser -CertPassword 비밀번호 -Verbose
dir -경로 C:\Certs -필터 *.cer | 가져오기 인증서 -CertFile $_ -StoreNames AuthRoot, 루트 -LocalMachine -Verbose
스크립트 자체:
#requires -Version 2.0
function Import-Certificate
{
param
(
[IO.FileInfo] $CertFile = $(throw "Paramerter -CertFile [System.IO.FileInfo] is required."),
[string[]] $StoreNames = $(throw "Paramerter -StoreNames [System.String] is required."),
[switch] $LocalMachine,
[switch] $CurrentUser,
[string] $CertPassword,
[switch] $Verbose
)
begin
{
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Security")
}
process
{
if ($Verbose)
{
$VerbosePreference = 'Continue'
}
if (-not $LocalMachine -and -not $CurrentUser)
{
Write-Warning "One or both of the following parameters are required: '-LocalMachine' '-CurrentUser'. Skipping certificate '$CertFile'."
}
try
{
if ($_)
{
$certfile = $_
}
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $certfile,$CertPassword
}
catch
{
Write-Error ("Error importing '$certfile': $_ .") -ErrorAction:Continue
}
if ($cert -and $LocalMachine)
{
$StoreScope = "LocalMachine"
$StoreNames | ForEach-Object {
$StoreName = $_
if (Test-Path "cert:\$StoreScope\$StoreName")
{
try
{
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store $StoreName, $StoreScope
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
$store.Add($cert)
$store.Close()
Write-Verbose "Successfully added '$certfile' to 'cert:\$StoreScope\$StoreName'."
}
catch
{
Write-Error ("Error adding '$certfile' to 'cert:\$StoreScope\$StoreName': $_ .") -ErrorAction:Continue
}
}
else
{
Write-Warning "Certificate store '$StoreName' does not exist. Skipping..."
}
}
}
if ($cert -and $CurrentUser)
{
$StoreScope = "CurrentUser"
$StoreNames | ForEach-Object {
$StoreName = $_
if (Test-Path "cert:\$StoreScope\$StoreName")
{
try
{
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store $StoreName, $StoreScope
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
$store.Add($cert)
$store.Close()
Write-Verbose "Successfully added '$certfile' to 'cert:\$StoreScope\$StoreName'."
}
catch
{
Write-Error ("Error adding '$certfile' to 'cert:\$StoreScope\$StoreName': $_ .") -ErrorAction:Continue
}
}
else
{
Write-Warning "Certificate store '$StoreName' does not exist. Skipping..."
}
}
}
}
end
{ }
}
원천:수입증명서