Azure AD Policy SAML transformations using PowerShell

Ron Manthe 1 Reputation point
2022-02-22T03:22:59.13+00:00

Hello,

I am having issues getting my custom policy to work in PowerShell. I am trying to make two separate claim transformations for a SAML application. One is trying to strip all the leading zeros from the beginning of the SamAccountName and the other is removing the middle initial in the givenname field. My code is posted below. If anyone has any suggestions that would be great.

New-AzureADPolicy -Definition @('
{"ClaimsMappingPolicy":
{
"Version":1,"IncludeBasicClaimSet":"false",
"ClaimsSchema":[{"Source":"user","ID":"givenname"},
{"Source":"transformation","ID":"RemoveInitial","TransformationId":"RemoveTheInitial","SamlClaimType":"FIRST_NAME","JwtClaimType":"FIRST_NAME"},
{"Source":"user","ID":"surname","SamlClaimType":"LAST_NAME","JwtClaimType":"LAST_NAME"},
{"Source": "user","ID":"mail","SamlClaimType":"EMAIL","JwtClaimType":"EMAIL"},
{"Source":"user","ID":"onpremisessamaccountname"},
{"Source":"transformation","ID":"RemoveZeros","TransformationId":"RemoveTheZeros","SamlClaimType":"USER_ID","JwtClaimType":"USER_ID"}],
"ClaimsTransformations":[{"ID":"RemoveTheInitial","TransformationMethod":"RegexReplace","InputClaims":[{"ClaimTypeReferenceId":"givenname","TransformationClaimType":"sourceClaim"}],
"InputParameters":[{"ID":"regex","Value":".."},{"ID":"replacement","Value":""}],"OutputClaims":[{"ClaimTypeReferenceId":"RemoveInitial","TransformationClaimType":"outputClaim"}]},
{"ID":"RemoveTheZeros","TransformationMethod":"RegexReplace","InputClaims":[{"ClaimTypeReferenceId":"onpremisessamaccountname","TransformationClaimType":"sourceClaim"}],
"InputParameters":[{"ID":"regex","Value":"^0
"},{"ID":"replacement","Value":""}],"OutputClaims":[{"ClaimTypeReferenceId":"RemoveZeros","TransformationClaimType":"outputClaim"}]}]
}
}
') -DisplayName "Hearsay-Sandbox-SAML-Policy" -Type "ClaimsMappingPolicy"

New-AzureADPolicy : Error occurred while executing NewPolicy
Code: Request_BadRequest
Message: Property definition has an invalid value.
InnerError:
RequestId: 135eb08f-2ec3-485a-9659-e51a5014607c
DateTimeStamp: Tue, 22 Feb 2022 03:20:04 GMT
HttpStatusCode: BadRequest
HttpStatusDescription: Bad Request
HttpResponseStatus: Completed
At line:1 char:1

  • New-AzureADPolicy -Definition @('
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : NotSpecified: (:) [New-AzureADPolicy], ApiException
  • FullyQualifiedErrorId : Microsoft.Open.MSGraphBeta.Client.ApiException,Microsoft.Open.MSGraphBeta.PowerShell.NewPolicy
Windows for business Windows Server User experience PowerShell
Microsoft Security Microsoft Entra Microsoft Entra ID
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Ron Manthe 1 Reputation point
    2022-02-22T18:38:26.267+00:00

    Update:

    I tried creating the policy with just the middle name transformation and it didn't take it. I did not like my Regex value of "..*" Not sure why. I am trying to find another transformation method that works.


  2. Siva-kumar-selvaraj 15,721 Reputation points
    2022-02-28T19:22:00.143+00:00

    @Ron Manthe , My apologies for the delay in answering.

    Thanks for sharing your finding here which will benefit others in the community who are dealing with a similar problem. In addition, I would to like to share my findings here and hope this would also helpful.

    **RegEx to Remove Middle Initial in a Given Name field : **

    Example:1 Name for Example is John J Smith and Final outcome would be JohnSmith note: there is no spaces.

    "InputParameters": [ { "ID": "regex", "Value": " . " }, { "ID": "replacement", "Value": "" } ]

    Example:2 Name for Example is John J Smith and Final outcome would be John Smith note: there is a space between first and last name.

    "InputParameters": [ { "ID": "regex", "Value": " . " }, { "ID": "replacement", "Value": " " } ]

    RegEx to remove all the leading zeros :

    "InputParameters": [ { "ID": "regex", "Value": "^0" }, { "ID": "replacement", "Value": "" } ]

    -----
    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.