【问题标题】:Resource createdTime property missing in Azure Resource Graph ExplorerAzure 资源图资源管理器中缺少资源 createdTime 属性
【发布时间】:2020-06-03 12:25:57
【问题描述】:

我正在尝试通过 Azure Resource Graph Explorer 获取 Azure 资源的 createdTime 字段,但 Azure Resource Graph Explorer 似乎不支持此值。我在任何地方都找不到它。

奇怪的是resources 端点确实有这个值,所以它确实存在于某个地方。 请在此处查看此端点的文档:https://docs.microsoft.com/en-us/rest/api/resources/resources/list(查看 $expand URI 参数)。我测试了这个端点并且它有效。我可以在一个订阅中查看我所有资源的 createdTime。

那么为什么 Resource Graph Explorer 没有/公开这个字段呢?

【问题讨论】:

    标签: azure azure-resource-manager azure-rest-api


    【解决方案1】:

    资源图资源管理器提供有关可查询的 Azure 资源管理器资源类型和属性的可浏览信息。 Resource Graph Explorer 还提供了一个干净的界面,用于处理多个查询、评估结果,甚至将某些查询的结果转换为可以固定到 Azure 仪表板的图表。

    一些资源你可以看到如下图的创建时间,但是如果你想查询你需要给出详细的时间。您提供的文章是关于资源列表的。

    【讨论】:

    • 但是为什么会这样,例如虚拟机没有creationTime,但是我使用resourcelist API的时候,可以查到虚拟机的creationTime吗?
    【解决方案2】:

    对于我不知道的 Graph,但使用 PowerShell 或 Rest,您可以使用此 sniped 代码。

        $subscriptionID = "11111-111-1111-111111"
        $resourceGroupName = "myResourceGroup"
    
        #assumes you have an active Az CLI context authenticated to target subscription. Can also be done with Az PowerShell, but requires a  different token retrieval method
        $accessToken = az account get-access-token --query accessToken
    
        #specify target API endpoint
        $uri = "https://management.azure.com/subscriptions/$($subscriptionID)/resourcegroups/$($resourceGroupName)?api-version=2019-08-01&%24expand=createdTime"
    
        $headers = @{
          "Authorization" = "Bearer $($accessToken)"
         }
    
        #consume ARM endpoint
       $rgInfo = Invoke-RestMethod -Uri $uri -Headers $headers -Method 'GET'
    
       $creationDate = $rgInfo.createdTime
    

    来自michaeldroessler的代码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-21
      • 1970-01-01
      • 1970-01-01
      • 2016-04-10
      • 1970-01-01
      • 1970-01-01
      • 2016-12-23
      相关资源
      最近更新 更多