Skip to content

Instantly share code, notes, and snippets.

@gjyoung1974
Created January 31, 2017 21:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gjyoung1974/19e9125b5dcdb7776370bebe780a1b23 to your computer and use it in GitHub Desktop.
Save gjyoung1974/19e9125b5dcdb7776370bebe780a1b23 to your computer and use it in GitHub Desktop.
#################################################
# #
# A script to submit a batch of CSRs to a CA #
# #
#################################################
## put this script the directory with your certificate signing requetss
$files = Get-ChildItem ".\"
# be sure to adjust the $cmdArgs to reflect the appropriate certificate template
# and $CAName below
# before submitting your batch of requests
$cmdArgs = "-submit -attrib `"CertificateTemplate:WebServerSSLCertificates`""
$CAName = "acmeca01.corp.svbank.com\ACME Issuing CA"
## for each CSR in the directory, submit it to the CA in pending status
for ($i=0; $i -lt $files.Count; $i++) {
Write-Host $files[$i].FullName
try{
[Diagnostics.Process]$myProcess2 = [Diagnostics.Process]::Start('c:\windows\system32\certreq.exe', $cmdArgs + " " + "-config `"$CAName`"" + " " + $files[$i].FullName )
if($myProcess2.ExitCode){
# Throw an exception is command fails for any reason
Write-Host "**certutil" + $cmdArgs + " has failed!**"
Exit
}
$myProcess2.WaitForExit()
}
## if there's an error, print it out:
catch{
Write-Host "**Failed to run set certreq -submit .**"
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment