Skip to main content
 首页 » 编程设计

json之Azure 广告应用之以编程方式更新 list

2025年12月25日27insus

我正在尝试找到一种利用 json 文件通过 powershell 更新 Azure Ad 注册应用程序 list 的方法。

Json 文件包含所有应用程序角色,我想简单地将应用程序角色:[] 直接注入(inject)到应用程序角色括号中

有没有办法通过 power shell 或 CLI 实现此目的?

请您参考如下方法:

是的,您可以通过 PowerShell 更新 Azure AD 应用程序的 list 。

为了添加应用程序角色,这里有一个 PowerShell 脚本。

如果您在创建新应用程序时尝试执行此操作,只需使用 New-AzureADApplication 而不是 Set-AzureADApplication

Connect-AzureAD -TenantId <Tenant GUID> 
 
# Create an application role of given name and description 
Function CreateAppRole([string] $Name, [string] $Description) 
{ 
    $appRole = New-Object Microsoft.Open.AzureAD.Model.AppRole 
    $appRole.AllowedMemberTypes = New-Object System.Collections.Generic.List[string] 
    $appRole.AllowedMemberTypes.Add("User"); 
    $appRole.DisplayName = $Name 
    $appRole.Id = New-Guid 
    $appRole.IsEnabled = $true 
    $appRole.Description = $Description 
    $appRole.Value = $Name; 
    return $appRole 
} 
 
# ObjectId for application from App Registrations in your AzureAD 
$appObjectId = "<Your Application Object Id>" 
$app = Get-AzureADApplication -ObjectId $appObjectId 
$appRoles = $app.AppRoles 
Write-Host "App Roles before addition of new role.." 
Write-Host $appRoles 
 
$newRole = CreateAppRole -Name "MyNewApplicationRole" -Description "This is my new Application Role" 
$appRoles.Add($newRole) 
 
Set-AzureADApplication -ObjectId $app.ObjectId -AppRoles $appRoles