Export MetaData.xml with Powershell on a ADFS 3.0 server
To be able to configure SAML SSO using ADFS as Identity Provider you need the metadata.xml from your ADFS server.
Because I love consistency and simple scripts I’d like to share 4 simple rules to export your metadata.xml from your ADFS server.
#Export MetaData XML $mUrl = (Get-ADFSEndpoint | where Protocol -eq "Federation Metadata").FullUrl.ToString() $httpHelper = new-object System.Net.WebClient $metadataAsString = $httpHelper.DownloadString($mUrl) $httpHelper.DownloadFile($mUrl , "C:\Users\$($env:username)\Desktop\metadata.xml")
Awesome stuff thank you!
Greatly appreciated. worked perfect
Great script, success on first run, thanks.
One change I’d make is to the DownloadFile portion. Since multiple users with the same username but different domains can login to a single machine, it’s better to use $env:USERPROFILE instead of C:\Users\$($env:username).
In my case, I had logged in as the domain administrator but the metadata was going to the local administrator desktop. It didn’t take me too long to see the issue, but I think it would make this much better to use the $env:userprofile variable which will have the current location in it all the time.
I changed the last line as follows, then it worked perfectly:
$httpHelper.DownloadFile($mUrl , “$($env:USERPROFILE)\Desktop\metadata.xml”)