Azure Automation Account, Tags and Runbook

Hi there

You can maintain your Azure Resources clean to avoid high billing invoices.

You will need the following:

  1. Azure Tag flagging your Azure Resources with YYYY-MM-DD format
  2. Azure Automation Account
  3. Schedule
  4. Azure Resource (i.e.: azure storage account with tag expireOn set to date you want to test)

Steps

Configure Azure Tags properly on the Azure Resource you’re about to evaluate the following steps. – Check this article.

Create Azure Automation Account

Log on Azure Portalcreate free account

Go to the Azure Marketplace and search for “automation” and click on it

Create the Azure Automation Account

Create the Runbook

Paste the proper PowerShell script from @Fboucher – Great thanks for the awesome PowerShell Script.

Create the Schedule

TIP! Check the storage account before it is deleted by the Runbook.

TIP! Check the storage account (used to be deleted: it has the expireOn tag set on)

Import modules required

To import modules required first you need to save modules locally on your PC

#save modules offline
mkdir c:\temp\azure\modules\
Save-Module -Name Az.Accounts -Path c:\temp\azure\modules\
Save-Module Az.ResourceGraph -Path c:\temp\azure\modules\
Save-Module Az.Resources -Path c:\temp\azure\modules\

Compact each folder to module-name.zip

Now you are ready to import the modules

Go the the Modules under Runbook blade

select add module (+ add module)

At upload file (.zip format, 100 MB max size) and locate the folder c:\temp\azure\modules\

Import modules on the following order one after another

  1. Az.Accounts
  2. Az.ResourceGraph
  3. Az.Resources

Wait for time and date scheduled to check the Runnbook execution

As you can see the first attempt failed on my LAB (I hadn’t imported the PowerShell modules).

After I fixed the PowerShell modules import – the next schedule run without issues.

Validate that the storage account has gone (ATTENTION: wrong use of this script on production could cause a disaster). Have Backup policy and routine implemented (ASR – Azure Site Recovery or Backup)


thanks,

Thiago Beier
TwitterLinkedInFacebookRSS