How to export the AD FS token-signing certificate with PowerShell

It's not something you need to do very often (an example is you need this when setting up SharePoint for claims based auth with AD FS) but there is no cmdlet to do this.

So here is the PowerShell to export the AD FS token-signing certificate.

A.

$certRefs=Get-AdfsCertificate -CertificateType Token-Signing

$certBytes=$certRefs[0].Certificate.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert)

[System.IO.File]::WriteAllBytes("c:\foo.cer", $certBytes)