Created
June 26, 2021 20:39
-
-
Save rezarahimian/08b47e9cbca6ebe24f08fb3cbdaa5849 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Inf = @" | |
[NewRequest] | |
Subject="CN=adfs.infra.private,O=Local,OU=IT,C=US" | |
KeySpec = 1 | |
KeyLength = 2048 | |
HashAlgorithm = SHA256 | |
Exportable = TRUE | |
MachineKeySet = TRUE | |
SMIME = False | |
PrivateKeyArchive = FALSE | |
UserProtected = FALSE | |
UseExistingKeySet = FALSE | |
ProviderName = "Microsoft RSA SChannel Cryptographic Provider" | |
ProviderType = 12 | |
RequestType = PKCS10 | |
KeyUsage = 0xa0 | |
Silent = True | |
FriendlyName = "ADFS Farm Certificate" | |
[Extensions] | |
2.5.29.17 = "{text}" | |
_continue_ = "DNS=adfs.infra.private&" | |
_continue_ = "DNS=adfs1.infra.private&" | |
_continue_ = "DNS=adfs2.infra.private&" | |
[EnhancedKeyUsageExtension] | |
OID=1.3.6.1.5.5.7.3.1 | |
"@ | |
$InfFile = Join-Path -Path $env:TEMP -ChildPath 'request.inf' | |
$Inf | Out-File -FilePath $InfFile -Force | |
Write-Verbose -Message ('Exported Inf file to {0}...' -f $InfFile) | |
$CsrFile = Join-Path -Path $env:TEMP -ChildPath 'request.csr' | |
$Cmd = 'certreq.exe' | |
$Arg = ('-new -f "{0}" "{1}"' -f $InfFile, $CsrFile) | |
Start-Process -FilePath $Cmd -ArgumentList $Arg -Wait | |
Write-Host ('Executed : {0} {1}' -f $Cmd, $Arg) | |
$CerFile = Join-Path -Path $env:TEMP -ChildPath 'request.cer' | |
$Arg = ('-submit -f -attrib "CertificateTemplate:WebServer" "{0}" "{1}"' -f $CsrFile, $CerFile) | |
Start-Process -FilePath $Cmd -ArgumentList $Arg -Wait | |
Write-Host ('Executed : {0} {1}' -f $Cmd, $Arg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment