Install the Azure Virtual Machine Agent in offline mode
The Azure Virtual Machine Agent (VM Agent) provides useful features, such as local administrator password reset and script pushing. This article shows you how to install the VM Agent for an offline Windows virtual machine (VM).
When to use the VM Agent in offline mode
Install the VM Agent in offline mode in the following scenarios:
- The deployed Azure VM doesn't have the VM Agent installed or the agent isn't working.
- You forgot the administrator password for the VM or you can't access the VM.
How to install the VM Agent in offline mode
Use the following steps to install the VM Agent in offline mode.
You can automate the process of installing the VM Agent in offline mode. To do this, use the Azure VM Recovery Scripts. If you choose to use the Azure VM Recovery Scripts, you can use the following process:
- Skip step 1 by using the scripts to attach the OS disk of the affected VM to a recovery VM.
- Follow steps 2–10 to apply the mitigations.
- Skip step 11 by using the scripts to rebuild the VM.
- Follow step 12.
Step 1: Attach the OS disk of the VM to another VM as a data disk
Delete the VM. Be sure to select the Keep the disks option when you delete the VM.
Attach the OS disk as a data disk to another VM (known as a troubleshooter VM). For more information, see Attach a data disk to a Windows VM in the Azure portal.
Connect to the troubleshooter VM. Open Computer management > Disk management. Confirm that the OS disk is online and that drive letters are assigned to the disk partitions.
Step 2: Modify the OS disk to install the Azure VM Agent
Make a remote desktop connection to the troubleshooter VM.
On the OS disk that you attached, browse to the \windows\system32\config folder. Copy all of the files in this folder as a backup, in case a rollback is required.
Start the Registry Editor (regedit.exe).
Select the HKEY_LOCAL_MACHINE key. On the menu, select File > Load Hive:
Browse to the \windows\system32\config\SYSTEM folder on the OS disk that you attached. For the name of the hive, enter BROKENSYSTEM. The new registry hive is displayed under the HKEY_LOCAL_MACHINE key.
Browse to the \windows\system32\config\SOFTWARE folder on the OS disk that you attached. For the name of the hive software, enter BROKENSOFTWARE.
If the Attached OS disk has the VM agent installed, perform a backup of the current configuration. If it does not have VM agent installed, move to the next step.
Rename the \windowsazure folder to \windowsazure.old.
Export the following registries:
Use the existing files on the troubleshooter VM as a repository for the VM Agent installation. Complete the following steps:
From the troubleshooter VM, export the following subkeys in registry format (.reg):
Edit the registry files. In each file, change the entry value SYSTEM to BROKENSYSTEM (as shown in the following images) and save the file. Remember the ImagePath of the current VM agent. We will need to copy the corresponding folder to the attached OS disk.
Import the registry files into the repository by double-clicking each registry file.
Confirm that the following three subkeys are successfully imported into the BROKENSYSTEM hive:
Copy the installation folder of the current VM Agent to the attached OS disk:
On the OS disk that you attached, create a folder named WindowsAzure in the root path.
Go to C:\WindowsAzure on the troubleshooter VM, look for any folder with the name C:\WindowsAzure\GuestAgent_X.X.XXXX.XXX. Copy the GuestAgent folder that has latest version number from C:\WindowsAzure to the WindowsAzure folder in the attached OS disk. If you are not sure which folder should be copied, copy all GuestAgent folders. The following image shows an example of the GuestAgent folder that is copied to the attached OS disk.
Select BROKENSYSTEM. From the menu, select File > Unload Hive.
Select BROKENSOFTWARE. From the menu, select File > Unload Hive.
Detach the OS disk, and then recreate the VM by using the OS disk.
Access the VM. Notice that the RdAgent is running and the logs are being generated.
If you created the VM by using the Resource Manager deployment model, you're done.
Use the ProvisionGuestAgent property for classic VMs
If you created the VM by using the classic model, use the Azure PowerShell module to update the ProvisionGuestAgent property. The property informs Azure that the VM has the VM Agent installed.
To set the ProvisionGuestAgent property, run the following commands in Azure PowerShell:
$vm = Get-AzureVM –ServiceName <cloud service name> –Name <VM name> $vm.VM.ProvisionGuestAgent = $true Update-AzureVM –Name <VM name> –VM $vm.VM –ServiceName <cloud service name>
Then run the
Get-AzureVM command. Notice that the GuestAgentStatus property is now populated with data:
Get-AzureVM –ServiceName <cloud service name> –Name <VM name> GuestAgentStatus:Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVMModel.GuestAgentStatus