Wednesday, July 4, 2018

Configure Azure Backup - using PowerShell

If you are configuring this for the first time then you need to register your Recovery Service provider with your subscription. For that you can run the below command.

Register-AzureRmResourceProvider -ProviderNamespace "Microsoft.RecoveryServices"


You can verify that the Providers registered successfully, using the following commands

Get-AzureRmResourceProvider -ProviderNamespace "Microsoft.RecoveryServices"


Create a recovery services vault

The Recovery Services vault is a Resource Manager resource, so you need to place it within a resource group. You can use an existing resource group, or create a resource group with the New-AzureRmResourceGroup cmdlet. When creating a resource group, specify the name and location for the resource group.


By default, the vault is set for Geo-Redundant storage. To further protect your data, this storage redundancy level ensures that your backup data is replicated to a secondary Azure region which is far away from the primary region.

To use this vault with the remaining steps, set the vault context with


Rather than creating the services one by one, you can copy paste the below mentioned Script into the PowerShell and run to create the Backup job. The details are mentioned below.

1. NameResourceGroup - Give the resource group name. you can give an existing resource group name or else create a ResourceGroup first.

2. Location - Give the correct Location name where you going to host your services. E.g. Australia East, UK South

3. VmName - Server Names .This is case Sensitive and make sure to give the VM name which you want to enable the protection.

4. NameRecoveryServicesVault – Give name for the Recovery service Vault

5. NamePolocy - Give a name for the Backup Policy

6. FriendlyName - Friendly name for the backup Container

Rest of the variables you can keep as it is and if there is any requirement to change the backup schedule you can edit that by go into the Backup policy.

You can copy paste the below scrip into the PowerShell and run to create the backup job.

PowerShell Script


#Variables for common values

$NameResourceGroup = "AAA-Production"

$NameRecoveryServicesVault = "A123RecoveryServicesVault"

$location = "WestUS2"

$NamePolocy = "DefaultPolicy"

$vmName = "AAA-Prod-SVR1"

$FriendlyName = "AAAProdSVR1"

#Create a recovery services vaults

New-AzureRmRecoveryServicesVault `

-ResourceGroupName $NameResourceGroup `

-Name $NameResourceGroup `

-Location $location

#Create a recovery services vaults

Get-AzureRmRecoveryServicesVault `

-Name $NameRecoveryServicesVault | Set-AzureRmRecoveryServicesVaultContext

# Enable backup for an Azure VM

$policy = Get-AzureRmRecoveryServicesBackupProtectionPolicy -Name $NamePolocy

Enable-AzureRmRecoveryServicesBackupProtection `

-ResourceGroupName $NameResourceGroup `

-Name $vmName `

-Policy $policy

# Start a backup job

$backupcontainer = Get-AzureRmRecoveryServicesBackupContainer `

-ContainerType "AzureVM" `

-FriendlyName $FriendlyName

$item = Get-AzureRmRecoveryServicesBackupItem -Container $backupcontainer

-WorkloadType "AzureVM"

Backup-AzureRmRecoveryServicesBackupItem -Item $item


Once this is completed, you can run Get-AzureRmRecoveryservicesBackupJob Command to check the status of the backup job.


Ps1 file can be download from here

Tuesday, July 3, 2018

Azure Recovery service Vault creation error New-AzureRmRecoveryServicesVault : Operation failed.

If you get an error when you are creating your Recovery service like below,

New-AzureRmRecoveryServicesVault : Operation failed.
ClientRequestId: 3f3842bd-7638-469e-a14c-46c230221d9b-2018-07-03 07:49:41Z-P
One or more errors occurred.
At line:1 char:1
+ New-AzureRmRecoveryServicesVault
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo          : CloseError: (:) [New-AzureRmRecoveryServicesVault], Exception
     + FullyQualifiedErrorId : Microsoft.Azure.Commands.RecoveryServices.NewAzureRmRecoveryServicesVault


It may be because of the wrong information which you have provided.

I have run the command in debug mode and found that the given Resource group is not created in the tenant.

Created the Resource group and then verified by running Get-AzureRmResourceGroup command.


Then check whether the location entered without any spaces.


Other thing that I want to highlight is the Resource Group. You have to enter the existing Resource group name and if the given Resource group is a new one, then create the Resource group first.

Ran the recovery service creation command again. No errors found