I regulalry need to check if my Azure virtual machines are turned off before leaving. Besides virtual machines, I also want to know in which pricing level my web sites, Azure SQL Databases, etc are running. I want to know if I have an HDInsight cluster running.
So I created an Azure automation job that checks the subscriptions at 6pm every day.
Here is how it looks:
You can start using Azure automation by following the instructions available here:
The script will need to get access to the subscriptions.
So I created a management certificate. One way to do so is explained in this blog post by Keith Mayer.
In my case, here is how my environment looks:
In Azure automation, the same certificate is declared in the assets:
Here is how the script itself:
# Get the Azure management certificate that is used to connect to this subscription
$Certificate = Get-AutomationCertificate -Name 'azure-admin.3-4.fr'
if ($Certificate -eq $null)
throw "Could not retrieve '$AzureConn.AutomationCertificateName' certificate asset. Check that you created this first in the Automation service."
$Certificate = $using:Certificate
$subscriptions = (('Azdem169A44055X','0fa8xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'),
foreach ($subscription in $subscriptions)
$subscriptionName = $subscription
$subscriptionId = $subscription
echo "------- Subscription $subscriptionName ----------"
# Set the Azure subscription configuration
Set-AzureSubscription -SubscriptionName $subscriptionName -SubscriptionId $subscriptionId -Certificate $Certificate
Select-AzureSubscription -Current $subscriptionName
$vms = @()
foreach ($s in Get-AzureService)
$vms += Get-AzureVm -ServiceName $s.ServiceName
echo "--- Virtual Machines ---"
$vms | select servicename, Name, PowerState | format-table
echo "--- HDInsight clusters ---"
$hclusters | format-table
echo "--- Web Sites ---"
$webs | select Name, SiteMode | sort Name | format-table
$dbs = @()
foreach ($s in Get-AzureSqlDatabaseServer)
$dbs += Get-AzureSqlDatabase -ServerName $s.ServerName
echo "--- SQL Databases ---"
$dbs | select Name, Edition, MaxSizeinGb | format-table
NB: I have obfuscated the subscription ids.
You can change the script for your own usage. You would need to change the certificate name (mine is azure-admin.3-4.fr), the names and ids of your subscriptions).