azure automation

Azure – Audit report (Azure automation runbook)

The PowerShell script is an Azure automation runbook that pulls the below data and populates the data into a CSV file. The script then summarizes the data into an email’s body and sends an email to the recipient with the CSV files as attachments.

If the Azure automation runbook is scheduled to run every day, you will get a summary/high-level view of what is happening in your environment to your email box. The email could be the first report any organization’s high management would desire to look at.

1. Count of De-allocated Azure virtual machines

2. Count of Running Azure virtual machines

3. Count of Stopped Azure virtual machines

4. Count of Azure virtual machines that do not have native backup configured (Azure Back up and Recovery service)

5. Count of Inbound Security rules that causes vulnerability

Download the script


Sample Summary:

Screenshot from 2018-06-04 19-13-52

Email is sent via SendGrid service. You need to update the script with your SendGrid credentials.

You may choose a “Free Tier” pricing for SendGrid. Below is documentation to create a SendGrid account:

Note: The script is an Azure Automation runbook. You have to run it from an Azure Automation account.


If you would like me to add more data that would be useful as an Azure audit report, please let me know.


Click here to download my PowerShell scripts for Free !!

Click here for Azure tutorial videos !!



Azure – Server Inventory solution

This blog post is dedicated to IT Operations team and administrators who are managing Cloud Infrastructure. The recommended practice while providing managed service to any client is to have a CMDB (Configuration Management Database), which tracks the list of servers and the corresponding details, that we are managing for the client.

However, considering the dynamic nature of the cloud environment, it is a difficult task to maintain such a database. Manually updating the list of servers/server inventory is tedious and error-prone. The only solution is to have an automated approach to this problem.

Below is my solution:

The PowerShell script will extract virtual machines and their details. In this particular case, the script will consider virtual machines, which has tags (‘owner’,’Manju’). That is, I want to manage virtual machines owned only by me. You can go ahead and make changes to the script if you have a different requirement.

Next, the script will write the data into an Azure table. Remember, that the Azure table has to be created before running the script. Another option is Azure Cosmos DB.

Next, you can upload this script to your Azure Automation account or a dedicated windows server. Then, schedule this script to run every one hour to track your server inventory.

The script uses cmdlets from the “AzureRmStorageTable” PowerShell module.

Execute “Install-Module AzureRmStorageTable” to install the module.

Note: You have to alter the script when you schedule the script. The login mechanism is different for “Azure Automation” and “Task scheduler via Windows server”. The login mechanism of the below script is to execute it directly (manually) from PowerShell console or PowerShell ISE.



# Author: Manjunath Rao
# Date: Febuary 13, 2018

# Install-Module AzureRmStorageTable –>> THIS MODULE NEEDED

# Login to Azure
## Code to create Azure table storage context
$azure_table_storage_account_name = “xxx”
$azure_table_name = “xxx”
$azure_table_partitionKey = “xxx”
$azure_table_rowkey = “xxx”

$azure_table_resource_group = “xxx”

$storage_account_context = (Get-AzureRmStorageAccount -ResourceGroupName $azure_table_resource_group -Name $azure_table_storage_account_name).Context

$azure_table_object = Get-AzureStorageTable -Name $azure_table_name -Context $storage_account_context


# Getting all the resource group
$resource_group_list = Get-AzureRmResourceGroup

# Iterating through the resource group
foreach($resource_group_list_iterator in $resource_group_list){

# Since the solution applies for virtual machines,
# obtain the list of virtual machines for the resource group
$virtual_machine_list = get-azurermvm -ResourceGroupName $resource_group_list_iterator.ResourceGroupName

# Proceed only when resource group contains virtual machines
if(!($virtual_machine_list -eq $null)){

# Iterate through the virtual machine list
foreach($virtual_machine_list_iterator in $virtual_machine_list){

# Creat an unique ID by concatinating ‘Resource Group name’ and ‘Virtual Machine name’
$unique_id = $resource_group_list_iterator.ResourceGroupName + $
#Write-Host $unique_id
$tag_list = $virtual_machine_list_iterator.Tags

$tag_list.GetEnumerator() | foreach {
#write-host $_.key
#Write-Host $_.value
#write-host “”

$partitionKey1 = $unique_id

if($_.key -eq ‘owner’ -and $_.value -eq ‘manju’) {
#write-host “true”
$virtual_machine_name = $virtual_machine_list_iterator.Name.ToString()
$virtual_machine_resource_group_name = $resource_group_list_iterator.ResourceGroupName.ToString()
$virtual_machine_location = $virtual_machine_list_iterator.Location.ToString()
$virtual_machine_size = $virtual_machine_list_iterator.HardwareProfile.VmSize.ToString()
$virtual_machine_operating_system = $virtual_machine_list_iterator.StorageProfile.ImageReference.Offer.ToString()


$hash = @{}
#$hash.add(‘currentDate’, $current_date)

# Write data into azure table
Add-StorageTableRow -table $azure_table_object -partitionKey (“CA1”) -rowKey ([guid]::NewGuid().tostring()) -property $hash






On the other hand, if you would like to fetch inventory details, and just save it in an excel sheet, I have the perfect scripts that do the job for you:


Click here to download my PowerShell scripts for Free !!