We are excited to announce that the IIS.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

Generating CSR using Powershell - possible? [Answered]RSS

8 replies

Last post Jun 14, 2013 06:32 AM by fab777

  • Generating CSR using Powershell - possible?

    Oct 08, 2011 02:07 AM|GrZeCh|LINK

    Hello,

    is this possible to generate CSR request for SSL certificate using Powershell?

    Regards

    csr iis7 powershell

  • Re: Generating CSR using Powershell - possible?

    Oct 10, 2011 09:12 AM|ServerIntellect_BH|LINK

    Hello,

    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:

    http://technet.microsoft.com/en-us/library/cc725793(WS.10).aspx

    Please let me know if you have any questions!

    -Brock

    Brock Hensley
  • Re: Generating CSR using Powershell - possible?

    Oct 18, 2011 04:42 AM|GrZeCh|LINK

     Thank you

  • Re: Generating CSR using Powershell - possible?

    Dec 29, 2011 09:42 AM|fab777|LINK

     Hi,

    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 = @"
        [NewRequest]`r
        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

    PowerShell ssl csr

    This message is provided "AS IS" with no warranties... But you can still mark it as answer if it's helped you.
    Fabrice ZERROUKI
    Wanna chill out? Here: JAHSound.net
  • Re: Generating CSR using Powershell - possible?

    Dec 29, 2011 09:47 AM|GrZeCh|LINK

    Didn't tested (I don't need it anymore) but thank you for responding.
  • Re: Generating CSR using Powershell - possible?

    Dec 29, 2011 09:54 AM|fab777|LINK

     No problem, maybe it will help someone else...

    This message is provided "AS IS" with no warranties... But you can still mark it as answer if it's helped you.
    Fabrice ZERROUKI
    Wanna chill out? Here: JAHSound.net
  • Re: Generating CSR using Powershell - possible?

    Aug 08, 2012 02:41 PM|vlozupone|LINK

    Hi fab777,

    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.

    Thanks

     

  • Re: Generating CSR using Powershell - possible?

    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 andrew.parker@globalsystemsstrategies.com

  • Re: Generating CSR using Powershell - possible?

    Jun 14, 2013 06:32 AM|fab777|LINK

    Hi,

    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:

    $HostHeader="www.example.com"
    $WebsiteName="MyWebsite"



    This message is provided "AS IS" with no warranties... But you can still mark it as answer if it's helped you.
    Fabrice ZERROUKI
    Wanna chill out? Here: JAHSound.net