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

Filipa Alves 11 Reputation points

I have this script:

Access token

$token = Get-AzAccessToken -TenantId $Tenant
$headers = @{ "Authorization" = "Bearer $($token.Token)" }
$restUri = "$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

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
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. :

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

    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


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