Skip to content

Instantly share code, notes, and snippets.

@nivleshc
Last active August 12, 2018 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nivleshc/2a86e632b9114cbeae915c65c2e0cbff to your computer and use it in GitHub Desktop.
Save nivleshc/2a86e632b9114cbeae915c65c2e0cbff to your computer and use it in GitHub Desktop.
<#AddToADFSFarm.ps1
#>
param (
$DomainName,
$PrimaryADFSServer,
$AdfsSvcUsername
)
#the adfs service account password is encrypted and stored in a local folder
$localpath = "C:\Program Files\WindowsPowerShell\Modules\Certificates\"
$Key = (3,4,2,3,56,34,254,222,1,1,2,23,42,54,33,233,1,34,2,7,6,5,35,43)
#lets get the password and decrypt it
#get the adfs password first
$adfspassword = Convertto-SecureString -String (Get-Content -Path $($localpath+"adfspass.key")) -key $key
$AdfsSvcCreds = New-Object System.Management.Automation.PSCredential($($DomainName+"\"+$AdfsSvcUsername), $adfspassword)
#install the certificate that will be used for ADFS Service
Import-PfxCertificate -Exportable -Password $adfspassword -CertStoreLocation cert:\localmachine\my -FilePath $($localpath+"adfs_certificate.pfx")
#get thumbprint of certificate
$cert = Get-ChildItem -Path Cert:\LocalMachine\my | ?{$_.Subject -eq "CN=fs.adfsfarm.com, OU=Free SSL, OU=Domain Control Validated"}
#Configure ADFS
Import-Module ADFS
Add-AdfsFarmNode -CertificateThumbprint $cert.thumbprint -ServiceAccountCredential $AdfsSvcCreds -PrimaryComputerName $PrimaryADFSServer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment