我必须使用 KQL 和 Azure 资源图查询为 PowerBI 仪表板列出名称中包含“test”的所有应用程序注册及其所有者。它尝试了文档中的不同风格,看起来像这样,但没有成功:
aadApplications
| project ApplicationId = appId, DisplayName, CreatedTime = createdDateTime
| join kind=leftouter (
AadApplicationOwners
| project ApplicationId = appId, Owner = userPrincipalName
) on ApplicationId
| summarize Owners = make_set(Owner), AppRoles = make_set(appRoleDisplayNames) by ApplicationId, DisplayName, CreatedTime
| project ApplicationID, Owners = tostring(Owners), DisplayName, AppRoles = tostring(AppRoles), CreatedTime
注意:AAD 应用程序是 Azure Active Directory 服务中的对象,而不是 Azure 资源。请参阅 AdamMarczakIO 的博客。
因此,或者您可以使用 PowerShell 或 CLI 或 Rest API 来查询 Azure Active Directory 应用程序。
要列出包含“test”的应用程序以及应用程序的所有者及其详细信息,请使用以下 PowerShell 脚本:
Connect-MgGraph
# Fetch applications containing "test" in their name
$applications = Get-MgApplication | Where-Object { $_.DisplayName -like "*test*" }
$tableData = @()
foreach ($app in $applications) {
$owners = Get-MgApplicationOwner -ApplicationId $app.Id -ErrorAction SilentlyContinue
$ownerId = if ($owners) { $owners.Id } else { "" }
$ownerName = if ($owners) { $owners.DisplayName } else { "" }
$tableData += [PSCustomObject]@{
"Application ID" = $app.Id
"Application Name" = $app.DisplayName
"Owner ID" = $ownerId
"AppRoles" = $app.AppRoles
"Created Time" = $app.CreatedDateTime
}
}
$tableData | Format-Table -AutoSize "Application ID", "Application Name", "Owner ID", "AppRoles", "Created Time"
输出:
Application ID Application Name Owner ID AppRoles Created Time
XXX Test XXX XXX XXXX