Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Run the following commands to define the required stringsnewline string

    Code Block
    languagepowershell
    $NewLine = [System.Environment]::NewLine
  2. Run the following commands to create the temporary files: 

    Code Block
    languagepowershell
    $CertificateTemplateFile = New-TemporaryFile
    $CertificateRequestFile = New-TemporaryFile
  3. Run the following commands to define the certificate template:

    Code Block
    languagepowershell
    $CertificateTemplate = @'
    [Version]
    Signature="$Windows NT$"
      
    [NewRequest]
    Subject="CN=%Subject%"
    Exportable=TRUE
    MachineKeySet=TRUE
    KeyLength=2048
    KeySpec=AT_KEYEXCHANGE
      
    [Extensions]
    2.5.29.17="{text}"
    _continue_="DNS=%Subject%&"
    '@
  4. Run the following commands to update the subject in the certificate template: 

    Code Block
    languagepowershell
    $CertificateTemplate = $CertificateTemplate.Replace('%Subject%', $Subject)
  5. Run the following commands to add any optional DNS subject alternate names to the certificate template: 

    Code Block
    languagepowershell
    ForEach ($SubjectAlternateName in $SubjectAlternateNames) { $CertificateTemplate = '{0}{1}_continue_="DNS={2}&"' -f $CertificateTemplate, $NewLine, $SubjectAlternateName }
  6. Run the following commands to add any optional IP Address subject alternate names to the certificate template: 

    Code Block
    languagepowershell
    ForEach ($CertificateIPAddress in $CertificateIPAddresses) { $CertificateTemplate = '{0}{1}_continue_="IPAddress={2}&"' -f $CertificateTemplate, $NewLine, $CertificateIPAddress }
  7. Run the following commands to trim the certificate template:

    Code Block
    languagepowershell
    $CertificateTemplate = $CertificateTemplate -replace '&"\s*$', '"'
  8. Run the following commands to write the certificate template file:

    Code Block
    languagepowershell
    $Content | Out-File -FilePath $CertificateTemplateFile -Force
  9. Run the following commands to review the certificate template file: 

    Code Block
    languagepowershell
    Get-Content -Path $CertificateTemplateFile
  10. Run the following commands to create the certificate request file:

    Code Block
    languagepowershell
    certreq -new -f $CertificateTemplateFile $CertificateRequestFile
  11. Run the following commands to review the certificate request file: 

    Code Block
    languagepowershell
    Get-Content -Path $CertificateRequestFile
  12. Run the following commands to retrieve the certificate request file name: 

    Code Block
    languagepowershell
    Get-Item -Path $CertificateRequestFile

...