【问题标题】:Unexpected search result from Azure Search Graph Search-AzGraph vs Azure Resource Graph ExplorerAzure Search Graph Search-AzGraph 与 Azure Resource Graph Explorer 的意外搜索结果
【发布时间】:2020-07-11 01:03:52
【问题描述】:

我在使用 PowerShell 命令“Search-AzGraph”时遇到了一个奇怪的行为(错误?)。

当我使用“Azure Resource Graph Explorer”时,我没有遇到这个问题。

resourcecontainers
 | where type =~ 'microsoft.resources/subscriptions/resourcegroups'
 | join kind=leftouter (resources | project ResourceId=id, ResourceName=name, ResourceType=type, resourceGroup) on resourceGroup

(您可以将此 KQL 查询直接复制粘贴到您的 Azure Resource Graph Explorer 中,它会显示所有 Azure 资源及其 Azure 各自的订阅 ID

使用“Azure Resource Graph Explorer”,在“project”关键字之后显示我要查找的列,我设置“ResourceId”来显示资源的 Id。它工作正常。我可以看到列名更改的结果。

但在使用“Search-AzGraph”时,“ResourceId”值包含来自“resourcecontainers”而不是“resources”的值 id。 如果我删除“ResourceId=”,我会得到与“Azure Resource Graph Explorer”相同(正确)的结果,但要访问它,我需要使用属性“id1”。 这没什么大不了的,但我希望能够使用我自己的命名列。

任何人都有这种经验,或者我错过了一些东西来获得两种情况下的结果? 谢谢

【问题讨论】:

    标签: azure powershell azure-functions kql azure-resource-graph


    【解决方案1】:

    我终于找到了解决方法:

    resourcecontainers
    | where type =~ 'microsoft.resources/subscriptions/resourcegroups'
    | join kind=leftouter (resources | project ResourceId=id, ResourceName=name, ResourceType=type, resourceGroup) on resourceGroup
    | project ResourceGroupId=id, ResourceId, ResourceGroupName=name, ResourceName, tags
    

    我在“加入”之后添加了一个“项目”,以明确为“资源容器”中的“id”列命名,因此结果不会混淆“资源容器”和“资源”之间的结果(值)。

    这是我的 PowerShell 代码的完整示例,以防有人感兴趣:

    $resources = Search-AzGraph -Subscription $subscriptionId -Query "resourcecontainers
    | where type =~ 'microsoft.resources/subscriptions/resourcegroups'
    | join kind=leftouter (resources | project ResourceId=id, ResourceName=name, ResourceType=type, resourceGroup) on resourceGroup
    | project ResourceGroupId=id, ResourceId, ResourceGroupName=name, ResourceName, ResourceType, tags"
    
    foreach ($resource in $resources) {
      Write-Host "Resource Group Id: " $resource.ResourceGroupId
      Write-Host "  Resource Group Name: " $resource.ResourceGroupName
      Write-Host "  Resource Id: " $resource.ResourceId
      Write-Host "  Resource Name: " $resource.ResourceName
      Write-Host "  Resource Type: " $resource.ResourceType
    }
    

    【讨论】:

      猜你喜欢
      • 2020-09-01
      • 1970-01-01
      • 2013-01-30
      • 2020-04-27
      • 2021-01-20
      • 1970-01-01
      • 1970-01-01
      • 2020-06-08
      • 2017-12-05
      相关资源
      最近更新 更多