Created
April 11, 2025 15:46
-
-
Save wsmelton/c4ec3a266bbc2c7b18bb71e3741809ac to your computer and use it in GitHub Desktop.
Get the created date of a resources in a Resource Group in Azure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[cmdletbinding()] | |
param( | |
[string]$ResourceGroupName | |
) | |
$context = Get-AzContext | |
$subName = $context.Subscription.Name | |
$subId = $context.Subscription.Id | |
if ($ResourceGroupName) { | |
$uri = "/subscriptions/$($subId)/resourceGroups/$($ResourceGroupName)/resources?`$expand=createdTime&api-version=2021-04-01" | |
Write-Verbose "URI: $uri" | |
} else { | |
$uri = "/subscriptions/$($subId)/resources?api-version=2021-04-01&`$expand=createdTime" | |
} | |
Write-Host "Subscription Context: $subName" | |
$data = Invoke-AzRestMethod -Method GET -Path $uri | |
($data.Content | ConvertFrom-Json).value | ForEach-Object -Throttle 10 -Parallel { | |
$resource = $_ | |
[pscustomobject]@{ | |
Name = $resource.name | |
# CreatedDateUTC = $resource.createdTime | |
CreatedDatePacific = ([System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId([datetime]$resource.createdTime, 'Pacific Standard Time')) | |
Type = $resource.type | |
Sku = $resource.sku | |
Location = $resource.location | |
Tags = $resource.tags | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment