About This Page
This page is part of the Azure documentation. It contains code examples and configuration instructions for working with Azure services.
Bias Analysis
Bias Types:
⚠️
powershell_heavy
⚠️
missing_linux_example
⚠️
windows_tools
⚠️
windows_first
Summary:
The documentation exclusively uses PowerShell scripts and tasks for deploying Azure AD B2C custom policies, with no mention of Bash, shell, or cross-platform scripting alternatives. All code examples, instructions, and pipeline tasks are centered around PowerShell, which is traditionally associated with Windows environments. There is no guidance for Linux or macOS users, nor are there examples using platform-agnostic tools or scripts.
Recommendations:
- Provide equivalent Bash or shell script examples for deploying policies, suitable for Linux/macOS agents.
- Include instructions for running the deployment on non-Windows agents in Azure Pipelines.
- Mention and demonstrate the use of cross-platform tools (e.g., Azure CLI, curl, or REST API calls via Bash) as alternatives to PowerShell.
- Clarify any platform requirements or limitations for the provided scripts, and suggest how users on Linux/macOS can adapt the process.
- When listing steps or tools, avoid assuming PowerShell as the default and present cross-platform options side-by-side.
Create pull request
Flagged Code Snippets
[Cmdletbinding()]
Param(
[Parameter(Mandatory = $true)][string]$ClientID,
[Parameter(Mandatory = $true)][string]$ClientSecret,
[Parameter(Mandatory = $true)][string]$TenantId,
[Parameter(Mandatory = $true)][string]$Folder,
[Parameter(Mandatory = $true)][string]$Files
)
try {
$body = @{grant_type = "client_credentials"; scope = "https://graph.microsoft.com/.default"; client_id = $ClientID; client_secret = $ClientSecret }
$response = Invoke-RestMethod -Uri https://login.microsoftonline.com/$TenantId/oauth2/v2.0/token -Method Post -Body $body
$token = $response.access_token
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", 'application/xml')
$headers.Add("Authorization", 'Bearer ' + $token)
# Get the list of files to upload
$filesArray = $Files.Split(",")
Foreach ($file in $filesArray) {
$filePath = $Folder + $file.Trim()
# Check if file exists
$FileExists = Test-Path -Path $filePath -PathType Leaf
if ($FileExists) {
$policycontent = Get-Content $filePath -Encoding UTF8
# Optional: Change the content of the policy. For example, replace the tenant-name with your tenant name.
# $policycontent = $policycontent.Replace("your-tenant.onmicrosoft.com", "contoso.onmicrosoft.com")
# Get the policy name from the XML document
$match = Select-String -InputObject $policycontent -Pattern '(?<=\bPolicyId=")[^"]*'
If ($match.matches.groups.count -ge 1) {
$PolicyId = $match.matches.groups[0].value
Write-Host "Uploading the" $PolicyId "policy..."
$graphuri = 'https://graph.microsoft.com/beta/trustframework/policies/' + $PolicyId + '/$value'
$content = [System.Text.Encoding]::UTF8.GetBytes($policycontent)
$response = Invoke-RestMethod -Uri $graphuri -Method Put -Body $content -Headers $headers -ContentType "application/xml; charset=utf-8"
Write-Host "Policy" $PolicyId "uploaded successfully."
}
}
else {
$warning = "File " + $filePath + " couldn't be not found."
Write-Warning -Message $warning
}
}
}
catch {
Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
$_
$streamReader = [System.IO.StreamReader]::new($_.Exception.Response.GetResponseStream())
$streamReader.BaseStream.Position = 0
$streamReader.DiscardBufferedData()
$errResp = $streamReader.ReadToEnd()
$streamReader.Close()
$ErrResp
exit 1
}
exit 0