Skip to content

Instantly share code, notes, and snippets.

@wsmelton
Created April 11, 2025 15:46
Show Gist options
  • Save wsmelton/c4ec3a266bbc2c7b18bb71e3741809ac to your computer and use it in GitHub Desktop.
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
[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