PowerShell script to submit certificate requests in bulk using certreq.exe

By | December 6, 2012

Here’s something I put together to handle bulk certificate requests for submission to an Enterprise CA using certreq.exe.  Enjoy!

#########################################################
#
# Name: Request-Certificates.ps1
# Author: Tony Murray
# Version: 1.0
# Date: 4/12/2012
# Comment: PowerShell script to submit certificate 
# requests in bulk using certreq.exe
#
#########################################################

# Specify the location of the request files
$csrdir = "C:\Certs\Requests\"
###

$files = Get-ChildItem $csrdir
$csrs = $files | ? {$_.extension -eq ".csr"}

# Parameters
$template = "WebServer" # must always use concatenated name format
$CA = "MyCAServer.mydomain.com\MyCAName"

foreach ($csr in $csrs)
{
    write-host "Requesting certificate $csr ..."
    $basename = $csr.basename
    # Specify the command line parameters for certreq.exe
    $parameters = "-config $CA -submit -attrib CertificateTemplate:$template " `
    + "$csrdir" + "$basename" + ".csr " +  "$csrdir" + "$basename" + ".cer " `
    +  "$csrdir" + "$basename" + ".p7b"
    # Start certreq.exe and pass in the parameters
    $request = [System.Diagnostics.Process]::Start( "certreq",$parameters )
    $request.WaitForExit()
    write-host "Finished request $csr"
    #sleep 10
} # end foreach

2 thoughts on “PowerShell script to submit certificate requests in bulk using certreq.exe

  1. Taylor Gibb

    Great Script, just somethings to point out, firstly you could use the Start-Process cmdlet if instead of the ::Start static method from the BCL. Secondly when you are

    Reply
  2. Taylor Gibb

    Great Script, just somethings to point out, firstly you could use the Start-Process cmdlet if instead of the ::Start static method from the BCL. Secondly when you are

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.