Indeed, resource groups don't have a creation timestamp.
But management operations are recorded in logs, and these logs can be retrieved with the Get-AzureRmLog
command.
Here is a PowerShell statement that goes through a subscription's resource groups and finds those that were created n or more days ago (from this gist):
$days = 7
$pointInTime = [DateTime]::Now.AddDays(-$days);
$horizon = $pointInTime.AddDays(-$days);
"===Removing resource groups created between $horizon and $pointInTime==="
# Get potential log entries
$logs = @()
$logs += Get-AzureRmLog -StartTime $horizon -EndTime $pointInTime -Status "Succeeded" -ResourceProvider "Microsoft.Resources" -WarningAction "SilentlyContinue" `
| Select-Object ResourceGroupName, ResourceId, @{Name="EventNameValue"; Expression={$_.EventName.Value}}, @{Name="OperationNameValue"; Expression={$_.OperationName.Value}}, EventTimestamp, @{Name="HttpVerb"; Expression={$_.HttpRequest.Method}} `
| Where-Object -FilterScript {$_.EventNameValue -EQ "EndRequest" -and $_.OperationNameValue -eq "Microsoft.Resources/subscriptions/resourcegroups/write" -and $_.HttpVerb -eq "PUT"} `
| Select-Object -ExpandProperty ResourceGroupName -Unique
"Expired resource groups (created BEFORE $pointInTime) -> $logs"
# Get recent log entries to remove from the list
$nologs = @()
$nologs += Get-AzureRmLog -StartTime $pointInTime -Status "Succeeded" -ResourceProvider "Microsoft.Resources" -WarningAction "SilentlyContinue" `
| Select-Object ResourceGroupName, ResourceId, @{Name="EventNameValue"; Expression={$_.EventName.Value}}, @{Name="OperationNameValue"; Expression={$_.OperationName.Value}}, EventTimestamp, @{Name="HttpVerb"; Expression={$_.HttpRequest.Method}} `
| Where-Object -FilterScript {$_.EventNameValue -EQ "EndRequest" -and $_.OperationNameValue -eq "Microsoft.Resources/subscriptions/resourcegroups/write" -and $_.HttpVerb -eq "PUT"} `
| Select-Object -ExpandProperty ResourceGroupName -Unique
"Resource groups created AFTER $pointInTime -> $nologs"
# remove any that were found to have recent creation
$rgs = $logs | Where-Object {$nologs -notcontains $_} | Select-Object @{Name="ResourceGroupName"; Expression={$_}} | Get-AzureRmResourceGroup -ErrorAction "SilentlyContinue"
"Existing resource groups to delete -> $($rgs | Select-Object -ExpandProperty ResourceGroupName)"
$rgs | Remove-AzureRmResourceGroup -Force -AsJob
It returns a list of the jobs that are running to delete the resource groups (they can take some time depending on their contents).