I am trying to automate b2c tenant custom policy creation under identity experience framework. Go to Azure Portal -> Azure AD B2C -> Policies -> Identity Experience Framework
But mg.graph module is giving pain while importing.
error: Import-Module -Name Microsoft.Graph -Force Import-Module : Function Find-MgTenantRelationshipTenantInformationByDomainName cannot be created because function capacity 4096 has been exceeded for this scope.
Note: I tried this in multiple PCs and ended up with same error.
# Authenticate to Microsoft Graph using client credentials
try {
$secureClientSecret = ConvertTo-SecureString -String $clientSecret -AsPlainText -Force
$credential = New-Object -TypeName Microsoft.Graph.PowerShell.Authentication.Credential
$credential.ClientId = $clientId
$credential.ClientSecret = $secureClientSecret
$credential.TenantId = $tenantName
Connect-MgGraph -Credential $credential -Scopes "Policy.ReadWrite.TrustFramework"
Write-Host "Successfully authenticated to Microsoft Graph."
} catch {
Write-Output "Failed to authenticate to Microsoft Graph, error: $($_.Exception.Message)"
throw
}
# Upload the policy file
try {
$policyName = "SignUpOrSignin-ODP-D2.xml"
$policyContent = Get-Content -Path $outputFilePath -Raw
Write-Host "Uploading policy: $policyName..."
$response = Invoke-MgGraphRequest -Uri ".0/trustFramework/policies/$policyName" `
-Method PUT `
-Body $policyContent `
-Headers @{ "Content-Type" = "application/xml" }
if ($response) {
Write-Host "Successfully uploaded policy: $policyName"
} else {
Write-Host "Failed to upload policy: $policyName"
}
} catch {
Write-Output "Failed to upload the policy file, error: $($_.Exception.Message)"
throw
}
I am trying to automate it to use powershell through azuredevops with a single without user interaction.
Thanks Krupa G
I am trying to automate b2c tenant custom policy creation under identity experience framework. Go to Azure Portal -> Azure AD B2C -> Policies -> Identity Experience Framework
But mg.graph module is giving pain while importing.
error: Import-Module -Name Microsoft.Graph -Force Import-Module : Function Find-MgTenantRelationshipTenantInformationByDomainName cannot be created because function capacity 4096 has been exceeded for this scope.
Note: I tried this in multiple PCs and ended up with same error.
# Authenticate to Microsoft Graph using client credentials
try {
$secureClientSecret = ConvertTo-SecureString -String $clientSecret -AsPlainText -Force
$credential = New-Object -TypeName Microsoft.Graph.PowerShell.Authentication.Credential
$credential.ClientId = $clientId
$credential.ClientSecret = $secureClientSecret
$credential.TenantId = $tenantName
Connect-MgGraph -Credential $credential -Scopes "Policy.ReadWrite.TrustFramework"
Write-Host "Successfully authenticated to Microsoft Graph."
} catch {
Write-Output "Failed to authenticate to Microsoft Graph, error: $($_.Exception.Message)"
throw
}
# Upload the policy file
try {
$policyName = "SignUpOrSignin-ODP-D2.xml"
$policyContent = Get-Content -Path $outputFilePath -Raw
Write-Host "Uploading policy: $policyName..."
$response = Invoke-MgGraphRequest -Uri "https://graph.microsoft/v1.0/trustFramework/policies/$policyName" `
-Method PUT `
-Body $policyContent `
-Headers @{ "Content-Type" = "application/xml" }
if ($response) {
Write-Host "Successfully uploaded policy: $policyName"
} else {
Write-Host "Failed to upload policy: $policyName"
}
} catch {
Write-Output "Failed to upload the policy file, error: $($_.Exception.Message)"
throw
}
I am trying to automate it to use powershell through azuredevops with a single without user interaction.
Thanks Krupa G
Share Improve this question asked Mar 21 at 20:00 GUNDRAJU KRUPA VANIGUNDRAJU KRUPA VANI 71 bronze badge 2- looking at the error message, it looks like the file you re trying to upload is more than 4MB or something? could you confirm the file size please. Could you try with whatever files are in the b2c starter pack to see if that work with your scripting ? – Thomas Commented Mar 21 at 20:46
- Could you please confirm do you want to upload custom policy file of SignUpOrSignIn.xml? – Pratik Jadhav Commented Mar 24 at 7:43
1 Answer
Reset to default 0Trying to automate b2c tenant custom policy creation under identity experience framework.
The error message you get might because of too many modules are installed in your system or the same module might be called multiple times.
Ensure that your SignUpOrSignIn.xml
has PolicyId
:
For adding SignUpOrSignIn.xml
to Identity Experience Framework.
Use below Modified Powershell Script
# Connect to Microsoft Graph with required permissions
#Import-Module Microsoft.Graph -Force
Connect-MgGraph -Scopes "Policy.ReadWrite.TrustFramework"
# Define policy details
$policyId = "B2C_1A_signup_signin-Demo"
$policyFile = "<YOUR_FILE_PATH\SignUpOrSignin.xml"
$outputFilePath = "<RESPONSE_OUTPUT>\policy-upload-response.xml"
# Verify if the file exists
if (-Not (Test-Path $policyFile)) {
Write-Host "Error: Policy file not found at $policyFile" -ForegroundColor Red
exit
}
# Read policy content
$policyContent = Get-Content -Path $policyFile -Raw
Write-Host "Uploading policy: $policyId.xml"
# Upload the policy to Microsoft Graph
try {
Invoke-MgGraphRequest -Uri "https://graph.microsoft/beta/trustFramework/policies/$policyId/`$value" `
-Method PUT `
-Body $policyContent `
-Headers @{ "Content-Type" = "application/xml" } `
-OutputFilePath $outputFilePath # This saves the response
Write-Host "Successfully uploaded policy: $policyId.xml" -ForegroundColor Green
Write-Host "Response saved to: $outputFilePath"
} catch {
Write-Host "Failed to upload policy: $policyId.xml. Error: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host "Policy upload process completed!"
Response:
Also, I've verified from the portal by Navigating to Azure Portal -> Azure AD B2C -> Policies -> Identity Experience Framework
If still issue persists update the graph modules to latest version using Update-Module Microsoft.Graph
and try the same.
Reference:
Azure AD B2C