Skip to content

Instantly share code, notes, and snippets.

@brlinton
Created August 29, 2016 16:45
Show Gist options
  • Save brlinton/cb169c8c3f358d86292294f1d9d82ae7 to your computer and use it in GitHub Desktop.
Save brlinton/cb169c8c3f358d86292294f1d9d82ae7 to your computer and use it in GitHub Desktop.
Print out all of the resources in a subscription (starting with SQL databases)
Login-AzureRmAccount
$OutFilePath = "D:\sql-databases.csv"
ForEach ($resourceGroup in Get-AzureRmResourceGroup)
{
ForEach ($sqlServer in Get-AzureRMSqlServer -ResourceGroupName $resourceGroup.ResourceGroupName)
{
ForEach($sqlDatabase in Get-AzureRMSqlDatabase -ServerName $sqlServer.ServerName -ResourceGroupName $resourceGroup.ResourceGroupName)
{
If($sqlDatabase.Name -ine "master")
{
$sqlServer.ServerName + "," + $sqlDatabase.DatabaseName + "," + $sqlDatabase.Edition + "," + $sqlDatabase.Location + "," + $sqlDatabase.CurrentServiceObjectiveName | out-file $OutFilePath -encoding ascii -append
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment