...
Run the following commands to define the required stringsnewline string:
Code Block language powershell $NewLine = [System.Environment]::NewLine
Run the following commands to create the temporary files:
Code Block language powershell $CertificateTemplateFile = New-TemporaryFile $CertificateRequestFile = New-TemporaryFile
Run the following commands to define the certificate template:
Code Block language powershell $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%&" '@Run the following commands to update the subject in the certificate template:
Code Block language powershell $CertificateTemplate = $CertificateTemplate.Replace('%Subject%', $Subject)Run the following commands to add any optional DNS subject alternate names to the certificate template:
Code Block language powershell ForEach ($SubjectAlternateName in $SubjectAlternateNames) { $CertificateTemplate = '{0}{1}_continue_="DNS={2}&"' -f $CertificateTemplate, $NewLine, $SubjectAlternateName }Run the following commands to add any optional IP Address subject alternate names to the certificate template:
Code Block language powershell ForEach ($CertificateIPAddress in $CertificateIPAddresses) { $CertificateTemplate = '{0}{1}_continue_="IPAddress={2}&"' -f $CertificateTemplate, $NewLine, $CertificateIPAddress }Run the following commands to trim the certificate template:
Code Block language powershell $CertificateTemplate = $CertificateTemplate -replace '&"\s*$', '"'
Run the following commands to write the certificate template file:
Code Block language powershell $Content | Out-File -FilePath $CertificateTemplateFile -Force
Run the following commands to review the certificate template file:
Code Block language powershell Get-Content -Path $CertificateTemplateFile
Run the following commands to create the certificate request file:
Code Block language powershell certreq -new -f $CertificateTemplateFile $CertificateRequestFile
Run the following commands to review the certificate request file:
Code Block language powershell Get-Content -Path $CertificateRequestFile
Run the following commands to retrieve the certificate request file name:
Code Block language powershell Get-Item -Path $CertificateRequestFile
...