是否有脚本可以查找应用程序权限?

问题描述 投票:0回答:1

您能否帮助查找应用程序权限名为 Mail.* 的 Azure 应用程序列表(可以是任何权限 Mail.Read/Mail.ReadWrite/Mail.Send/或任何其他权限)? 应该使用 Powershell 来进行此活动。

注意:某些应用程序可以拥有委派邮件*权限(我们不想要)。

谢谢

azure-powershell
1个回答
0
投票

这适用于分配给服务主体的权限...

$ManagedIDs = Get-MgServicePrincipal -All
$ManagedIDs.Count
$AllAppRoles = @()
ForEach ($ManagedID in $ManagedIDs) {
    $ManagedIDRoles = Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $ManagedID.Id
    $AssignedRoles = @()
    ForEach ($Role in $ManagedIDRoles) {
        $AssignedRoles += (Get-MgServicePrincipal -Filter "DisplayName eq '$($Role.ResourceDisplayName)'").AppRoles | 
            Where-Object {$_.Id -eq $Role.AppRoleId} | Select-Object @{N="Name";E={$Role.PrincipalDisplayName}}, @{N="Resource";E={$Role.ResourceDisplayName}}, Value, DisplayName, Description, ID
    } 
    $AllAppRoles += $AssignedRoles
}
$AllAppRoles.count
$AllAppRoles | Group-Object Value | Sort-Object Count -Descending | Select-Object Count, Name
$AllAppRoles | Where-Object {$_.Value -like "Mail.*"} | Format-Table
© www.soinside.com 2019 - 2024. All rights reserved.