IIS 7 and Above
Generating CSR using Powershell - possible?
Last post Jun 14, 2013 06:32 AM by fab777
Oct 08, 2011 02:07 AM|GrZeCh|LINK
is this possible to generate CSR request for SSL certificate using Powershell?
csr iis7 powershell
Oct 10, 2011 09:12 AM|ServerIntellect_BH|LINK
Generating certificates is not built into PowerShell directly; however, you can execute the necessary .exe's via PowerShell to accomplish your goal.
See the following article on how to use Certreq:
Please let me know if you have any questions!
Oct 18, 2011 04:42 AM|GrZeCh|LINK
Dec 29, 2011 09:42 AM|fab777|LINK
if you still need help to generate CSR, here is how I do it (with certreq):
$Date = (Get-Date).ToString('ddMMyyyy')
$ReqFile = "Cert_Req-$WebsiteName-" + "$Date" + ".req"
$InfFile = @"
Subject = "CN=$HostHeader"`r
KeySpec = 1
KeyLength = 2048
Exportable = TRUE`r
RequestType = CMC`r
Write-Host "Generating Certificate Request file..." -ForegroundColor Yellow;
$FinalInfFile = "Cert_Req_Inf-WebsiteName-" + "$Date" + ".inf"
New-Item $FinalInfFile -type file -value $InfFile
cmd /c "certreq -new $FinalInfFile $ReqFile"
Write-Host " "
Write-Host "Certificate request file for $WebsiteName successfully generated!" -foregroundcolor DarkGreen;
You'll just have to define $HostHeader and $WebsiteName
Dec 29, 2011 09:47 AM|GrZeCh|LINK
Dec 29, 2011 09:54 AM|fab777|LINK
No problem, maybe it will help someone else...
Aug 08, 2012 02:41 PM|vlozupone|LINK
Thank you very much for this script. I was wondering if you have any ideas why I'm getting this error on 2008 R2.
comment line not started with a # after I run the script. It creates the inf file but doesn't create the csr. There seems to be something wong with the inf file.
It works perfectly on Server 2003 btw.
Jun 13, 2013 01:42 PM|andrew.parker|LINK
You'll just have to define $HostHeader and $WebsiteName. Where in the script would make these modifications? I am new to the use of PowerShell.
Andrew Parker firstname.lastname@example.org
Jun 14, 2013 06:32 AM|fab777|LINK
you have to define a variable value before to call it.
In this example you can add these two lines at the begining of the script: