This script will download FederationMetadata.xml file on the ADFS server and bypass SSL certificate check.
Normally you would download FederationMetadata.xml via
Invoke-WebRequest "https://localhost/FederationMetadata/2007-06/FederationMetadata.xml" -OutFile "federationMetadata.xml"
But instead of this you receive following error message (if you’re using not properly trustable SSL certificate for ADFS FQDN metadata url):
Invoke-WebRequest : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
The right solution to bypass certificate client check is this (remember to run PowerShell as Administrator):
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} $WebClient = New-Object System.Net.WebClient $WebClient.DownloadString("https://localhost/FederationMetadata/2007-06/FederationMetadata.xml") | Out-File -FilePath "C:\federationMetadata.xml" -Encoding utf8