Generate CSR

Automation of CSR generation, uses certreq.exe

$Date = (Get-Date).ToString('ddMMyyyy')
$WebsiteName = "ToBeDefined"
$HostHeader = "ToBeDefined"

$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;
    }

Leave a Reply

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

Scroll to Top