Question

Difficulty: HardAzure Virtual Machine Backup Configuration

An administrator needs to automate the backup configuration of a new virtual machine named `vm-hr-prod` running Windows Server 2025 in the `South Central US` region. The administrator has already installed the Azure PowerShell `Az` module.

The administrator must meet the following requirements:
1. Create a new Recovery Services Vault named `rsv-hr-prod` in the same region.
2. Set the vault context for the current PowerShell session.
3. Enable backup protection for `vm-hr-prod` using the default backup policy named `DefaultPolicy`.
4. Trigger an immediate, ad-hoc backup of `vm-hr-prod`.

Which sequence of PowerShell commands should the administrator execute? To answer, arrange the actions in the correct order.

  1. 1New-AzRecoveryServicesVault -Name "rsv-hr-prod" -ResourceGroupName "rg-hr" -Location "southcentralus"
  2. 2Set-AzRecoveryServicesVaultContext -Vault (Get-AzRecoveryServicesVault -Name "rsv-hr-prod" -ResourceGroupName "rg-hr")
  3. 3policy=GetAzRecoveryServicesBackupProtectionPolicyName"DefaultPolicy"EnableAzRecoveryServicesBackupProtectionResourceGroupName"rghr"Name"vmhrprod"Policypolicy = Get-AzRecoveryServicesBackupProtectionPolicy -Name "DefaultPolicy" Enable-AzRecoveryServicesBackupProtection -ResourceGroupName "rg-hr" -Name "vm-hr-prod" -Policy policy
  4. 4item=GetAzRecoveryServicesBackupItemContainerTypeAzureVMWorkloadTypeAzureVMFriendlyName"vmhrprod"BackupAzRecoveryServicesBackupItemItemitem = Get-AzRecoveryServicesBackupItem -ContainerType AzureVM -WorkloadType AzureVM -FriendlyName "vm-hr-prod" Backup-AzRecoveryServicesBackupItem -Item item

Answer

The correct sequence of commands is: First, create the vault using New-AzRecoveryServicesVault. Second, set the vault context using Set-AzRecoveryServicesVaultContext. Third, retrieve the policy and enable backup using Get-AzRecoveryServicesBackupProtectionPolicy and Enable-AzRecoveryServicesBackupProtection. Fourth, retrieve the backup item and start the backup using Get-AzRecoveryServicesBackupItem and Backup-AzRecoveryServicesBackupItem.
The correct order establishes the prerequisite resources and session context before configuring backup policies and triggering backup actions. First, the Recovery Services Vault must be created. Second, the vault context must be set using Set-AzRecoveryServicesVaultContext so that subsequent backup commands know which vault to interact with. Third, the backup policy is retrieved, and backup protection is enabled for the VM. Finally, once the VM is protected, the backup item is retrieved, and an ad-hoc backup is executed.

Step-by-Step Solution

1
Execute New-AzRecoveryServicesVault.
Creates the Recovery Services Vault named rsv-hr-prod in the South Central US region.
You cannot perform any backup configuration or set the context without the target vault existing.
2
Execute Set-AzRecoveryServicesVaultContext.
Sets the vault context for the active PowerShell session.
Subsequent Azure Backup cmdlets in the Az module require the active vault context to be set to identify the vault container.
3
Execute Get-AzRecoveryServicesBackupProtectionPolicy and Enable-AzRecoveryServicesBackupProtection.
Associates the VM with the DefaultPolicy and registers the VM for protection.
You must enable backup protection on the VM before you can run any backup jobs on it.
4
Execute Get-AzRecoveryServicesBackupItem and Backup-AzRecoveryServicesBackupItem.
Launches the ad-hoc backup job immediately.
An ad-hoc backup can only be initiated on an item that is already protected and registered in the vault.

Key Concept

Azure Virtual Machine Backup Configuration using Azure PowerShell
Estimated Time:2m 0s
Rate this question