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")

 

5 comments on “Export MetaData.xml with Powershell on a ADFS 3.0 server”

  1. Janus says:

    Awesome stuff thank you!

  2. MaxWun says:

    SWEETNESS!

    1. Kris Castillo says:

      Greatly appreciated. worked perfect

  3. Sherwood Jefferson says:

    Great script, success on first run, thanks.

  4. Robert W. Rogier says:

    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”)

Leave a Reply

Your email address will not be published. Required fields are marked *

captcha

Please enter the CAPTCHA text

This site uses Akismet to reduce spam. Learn how your comment data is processed.