Get the createdTime and changedTime of one resource in Azure with Powershell

Filipa Alves 11 Reputation points
2022-04-28T11:32:06.453+00:00

I have this script:

Access token

$token = Get-AzAccessToken -TenantId $Tenant
$headers = @{ "Authorization" = "Bearer $($token.Token)" }
$restUri = "https://management.azure.com/subscriptions/$Subscription/resources?api-version=2021-04-01&$filter=resourceType eq 'Microsoft.KeyVault/vaults'&$expand=createdTime,changedTime"
$response = Invoke-RestMethod -Uri $restUri -Method GET -Headers $headers
$response

And I want to filter by resource and get the createdTime and changedTime, but I have two problems:
1- The filter doesn't filter anything
2- The response doesn't get the parameters createdTime and changedTime.

The response is this:
value : {@{id=/subscriptions/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/resourceGroups/cloud-shell-storage-southcentralus/providers/Microsoft.Storage/storageAccounts/XXXXXXXXX;
name=cs710032001dfc8766c; type=Microsoft.Storage/storageAccounts; sku=; kind=StorageV2; location=southcentralus; tags=}, @{id=/subscriptions/XXXXXXXXXXX/re
sourceGroups/DefaultResourceGroup-WEU/providers/Microsoft.OperationalInsights/workspaces/DefaultWorkspace-XXXXXXXXXXXXXXXXX-WEU;
name=DefaultWorkspace-XXXXXXXXXXX-WEU; type=Microsoft.OperationalInsights/workspaces; location=westeurope; tags=},
...}

You can see in the above response that the type is: Microsoft.Storage/storageAccounts and in my script I filter by this resource type: Microsoft.KeyVault/vaults.
And you see that the response doesn´t contain the createdTime or changedTime., as espected.

In your documentation, you have the filter and the expanded with createdTime and changedTime. :
https://learn.microsoft.com/en-us/rest/api/resources/resources/list

Could you please help me and clarify?

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,455 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,542 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 39,501 Reputation points
    2022-05-04T07:33:31.027+00:00

    Hi there,

    Could you please clarify what resource are you talking about?

    For example, get-azurermstorageaccount return created time. Get-AzureRmWebApp returns last modified.

    Get-AzureRmResourceGroup | Get-AzureRmResourceGroupDeployment - returns timestamp (for each deployment operation).

    In addition, the below thread discusses the same topic and you can have a look at it to get some valuable insights about this topic.

    Find the created by and created date for an azure object https://learn.microsoft.com/en-us/answers/questions/271292/find-the-created-by-and-created-date-for-an-azure.html

    -------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer–