Skip to content
Advertisement

Azure SQL Server Created Date

This could be the first of many questions I raise around Azure as I am currently on a mission to tidy up our Azure platform that has previously been setup by other teams.

Our SQL Servers that have been setup on Azure have had no tags setup and I want to setup some new tags now on all our existing SQL server resources. One of them being ‘Created Date’.

So far I have been unable to find a way of getting the create date of the resource.

I’m not fussed on how I get the info, portal, azure-cli or powershell I just need a way if its possible. I have looked in the ‘activity log’ in the portal, but as these resources were created more than 90 days ago, I’m not sure if this info is still available.

I know this is a relatively simple question but I’m having real issues finding the answer.

TIA

Advertisement

Answer

I can’t find a way of getting it at server level, but there is a creationDate property on the Azure SQL databases.

So if we assume that the master database on each server accurately reflects the server creation time (as it should be incepted at the same time):

$sqlServers = az sql server list | ConvertFrom-Json

foreach ($sqlServer in $sqlServers) {
    $databases = az sql db list --server $sqlServer.name --resource-group $sqlServer.resourceGroup | ConvertFrom-Json

    foreach ($database in $databases | Where-Object name -eq "master") {
        Write-Host "$($sqlServer.name)$($database.name) -> $($database.creationDate)"
    }
}
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement