Clone VMs after ASR Test Failover

If you want to clone a production environment on-prem to Azure and then, for example, test an upgrade or do new development on those servers, here is one way to do it.

My solution is using Azure Site Recovery (ASR) and a PowerShell script. It does not have any impact on the on-prem environment because I am using Test Failover in ASR which is starting the servers on a separate VNet in Azure which is not having any connectivity back on-prem. The Test Failover feature in ASR will make a clone of the on-prem servers in Azure and will not shut them down.

In ASR, as of today, you can only do one Test Failover at the time. This means that if you have done one Test Failover you cannot do another one while the first one is running. Because of this I am using a script in ASR to clone the Test Failover VMs so you can do more than one environment for testing.

Here is how I did it!

1.       First step is to install and configure ASR to replicate the servers that is going to be cloned When that is done, control that the servers are using Managed Disks. It they are not, change so they do.

2.       Next step is to create an Azure Automation Account and a Runbook for cloning the servers. Here is the script I use: My GitHub. If you are using my script, change the variables to fit your needs.

If you have issues with the script, update the Azure Automation Account modules and import the modules that are needed. Here is a screenshot of the modules I have tested the script with.

3.       When the servers have been replicated with ASR, create an ASR Recovery Plan and add the servers to a Group. Add the earlier created Runbook from Azure Automation as a Recovery Plan post step on the Group with the servers.

When this is done, do a Test Failover to test you Recovery Plan and clone of the servers.

Clone VMs in an Azure Resource Group

There are many ways to clone VMs from one Azure Resource Group to another. Here is one example that are using Azure Snapshots. The VMs, to clone, has to belong to the same Azure Region as where the copy should be created and has to use managed disks.

To get going with the script, download or copy it from my GitHub account. It works perfect in Azure Cloud Shell for PowerShell  as well as in a Azure Automation Runbook. Just remember to upgrade the modules before running it.

Here is a screenshot from a ready clone from Resource Group myvms-rg.


Use an Azure Function to add information to Log Analytics

This is an example how to add information from an Azure Function to Log Analytics with C#. I have used the C# code from the Log Analytics documentation and made some changes to fit my needs.

In this example I have chosen to use an http trigger and let the Function to take an json input. The input data is then added into the Log Analytics workspace.

Use an Azure Function to add information to Log Analytics1

Create an Azure Function as a HTTP trigger.

Use an Azure Function to add information to Log Analytics2

Paste the following code and replace the variables LogAnalyticsWorkspaceId and LogAnalyticsWorkspaceKey.

Add test json code in the “Request body” and test the Function by clicking Run.

Use an Azure Function to add information to Log Analytics3


Get started with Microsoft Azure Total Cost of Ownership (TCO) calculator

In an earlier post, I described how to install MAP Toolkit to do inventory of an IT environment and in this post, I will show how to get started to compare the cost for an on-prem environment to Azure.

To get started install MAP Toolkit and do an inventory as described in this earlier post. When this is done use the export function in MAP Toolkit to export the inventory into an Excel sheet.

Go to the page, Total Cost of Ownership (TCO) Calculator (Preview at the time of writing), and click Start Now to use the tool.

Open the MAP Toolkit inventory file and do the following modifications to it.

  1. Delete the top 3 rows with plain text.
  2. Remove any non-integer values in cores and RAM (System Memory) column.
  3. Save and close the file.

2 Get started with Microsoft Azure Total Cost of Ownership

Import the file by doing the following in the Total Cost of Ownership (TCO) Calculator.

  1. At the Inputs screen, select the Bulk Input radio button and select the MAP radio button.
  2. Press the Upload File button
  3. Confirm that the filename is shown on screen indicating that it is ready for upload. Enter the remaining Storage and Networking parameters and press Calculate.

1 Get started with Microsoft Azure Total Cost of Ownership

When the calculation has been done, you will have a report that looks something like this.

3 Get started with Microsoft Azure Total Cost of Ownership

Log Analytics View for Azure Automation DSC

Feel free to download and use my Log Analytics view for Azure Automation DSC. To get started with DSC please use the right menu on my blog and look through the examples. Also, before using this view the logs from Azure Automation DSC need to exist in Log Analytics. Please see my earlier post to push the logs into Log Analytics Link.

Picture of Log Analytics View

Log Analytics View for Azure Automation DSC

Link for download view: DSC Node Compliance Status (Last Hour)