Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Making this chunk of code a little cleaner. (Counting values).

$
0
0

Thanks so much! That worked perfectly. Just incase anyone is looking for a way to export/import a Claims Provider Trust on AD FS 2.x, in full, here is my script I finished.
#========================================================================
# Created with: SAPIEN Technologies, Inc., PowerShell Studio 2012 v3.1.22
# Created on: 8/30/2013 3:27 PM
# Created by: Troy D. Helms
# Filename: Import-CPTrust.ps1
#========================================================================

#Imports the PS Object in full from an export file made using the following line:
# Get-ADFSClaimProviderTrust -name "CPTrustName" | Export-CLIXML ExportedClaimsProviderTrust.xml
$CPTrust = Import-Clixml ExportedClaimsProviderTrust.xml

#Creates the "stub" ClaimsProviderTrust in ADFS with the most basic values. (It also puts in all TokenSigningCertificates at once!)
Add-ADFSClaimsProviderTrust -Identifier $CPTrust.Identifier -Name $CPTrust.Name -TokenSigningCertificate $CPTrust.TokenSigningCertificates

#Each of the following lines sets the values for the ClaimsProviderTrust if they aren't null to match the original export.
If ($CPTrust.AcceptanceTransformRules) {Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -AcceptanceTransformRules $CPTrust.AcceptanceTransformRules}
If ($CPTrust.AllowCreate) {Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -AllowCreate $CPTrust.AllowCreate}
If ($CPTrust.EncryptedNameIdRequired) {Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -EncryptedNameIdRequired $CPTrust.EncryptedNameIdRequired}
If ($CPTrust.EncryptionCertificate) {Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -EncryptionCertificate $CPTrust.EncryptionCertificate}
If ($CPTrust.EncryptionCertificateRevocationCheck) {Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -EncryptionCertificateRevocationCheck $CPTrust.EncryptionCertificateRevocationCheck}
If ($CPTrust.MetadataUrl) {Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -MetadataUrl $CPTrust.MetadataUrl}
If ($CPTrust.MonitoringEnabled) {Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -MonitoringEnabled $CPTrust.MonitoringEnabled}
If ($CPTrust.Notes) {Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -Notes $CPTrust.Notes}
If ($CPTrust.ProtocolProfile) {Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -ProtocolProfile $CPTrust.ProtocolProfile}
If ($CPTrust.RequiredNameIdFormat) {Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -RequiredNameIdFormat $CPTrust.RequiredNameIdFormat}
If ($CPTrust.SamlAuthenticationRequestIndex) {Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -SamlAuthenticationRequestIndex $CPTrust.SamlAuthenticationRequestIndex}
If ($CPTrust.SamlAuthenticationRequestParameters) {Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -SamlAuthenticationRequestParameters $CPTrust.SamlAuthenticationRequestParameters}
If ($CPTrust.SamlAuthenticationRequestProtocolBinding) {Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -SamlAuthenticationRequestProtocolBinding $CPTrust.SamlAuthenticationRequestProtocolBinding}
If ($CPTrust.SignatureAlgorithm) {Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -SignatureAlgorithm $CPTrust.SignatureAlgorithm}
If ($CPTrust.SignedSamlRequestsRequired) {Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -SignedSamlRequestsRequired $CPTrust.SignedSamlRequestsRequired}
If ($CPTrust.SigningCertificateRevocationCheck) {Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -SigningCertificateRevocationCheck $CPTrust.SigningCertificateRevocationCheck}
If ($CPTrust.WSFedEndpoint) {Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -WSFedEndpoint $CPTrust.WSFedEndpoint}

#This creates the SAMLEndpoints if there are any.
If ($CPTrust.SamlEndpoints) {
$endpoints = foreach ($endpoint in $CPTrust.SamlEndpoints) {New-ADFSSamlEndpoint -Protocol $endpoint.Protocol -Uri $endpoint.Location -Binding $endpoint.Binding -IsDefault $endpoint.IsDefault -Index $endpoint.Index -ResponseUri $endpoint.ResponseLocation}

Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -SamlEndpoint $endpoints
}

#The only values I have yet to understand how to migrate on a ClaimsProviderTrust is the ClaimsOffered & the Organization data.
#Claims offered SHOULD work using something like this line:
#If ($CPTrust.ClaimsOffered) {Set-ADFSClaimsProviderTrust -TargetName $CPTrust.name -ClaimOffered $CPTrust.ClaimsOffered}
#However, I can't make it work. Lots of trial and error, with no success. It's not important for what I'm doing, but it would be nice to handle it.
#Organization information doesn't seem to have a parameter on the Set-ADFSClaimsProviderTrust cmdlet to actually add it.
#I considered tossing that information into the NOTES section, since it's informational only anyway.


Viewing all articles
Browse latest Browse all 13067

Trending Articles