Script Sample - Azure Automation - Runbook for ASR Recovery Plan

@20aman    Sep 05, 2018

When you are automating Azure Site Recovery, you will be working with Azure Automation Runbooks. You will invoke these from within the Azure Site Recovery Plan. The input parameter to this Runbook will be a Recovery Plan Context, that will automatically be passed by the ASR Recovery Plan. This Recovery plan context will contain information like:

  1. Recovery Plan Name
  2. Failover Type
  3. Failover DIrection
  4. Subscription Name
  5. Resource Group Name
  6. VM Name

The Azure Automation Runbook should be able to receive this information and parse it.

Best Practice and this Script Sample

As a best practice, you should leverage the main Runbook to perform operational functions. E.g. If the automation that you want to trigger on Failover, requires connection to the company's internal network, then you would want it to run on a Hybrid worker (which will be connected to your internal network). As such, I recommend that the parsing of the recovery plan context should be done in another Runbook, which should be invoked by the main Runbook.

This sample PowerShell Runbook accepts the Recovery Plan context and passes it to the second Runbook. That Runbook may or may not run on a Hybrid worker.

Sample Recovery Plan Context

A sample Recovery Plan Context looks like below. Please note that this is formatted appropriately here. In the Runbook it will look flattened i.e. instead of multiple lines, the context will be contiguous and will be presented in a single long line. Its data type is Object when coming from ASR Recovery Plan.


Location of the Script

You can find this script in GitHub at this location: ASR-RunbookForRecoveryPlans.ps1

Runbook for Parsing the Recovery Plan Context

The Runbook for parsing the Recovery Plan Context is discussed here: Script Sample - Get VM's Information from ASR Context. The Runbook/script in that link is the one that is being invoked by the Runbook discussed in this blog post.

Comments powered by Disqus