Veeam Agent recovery in VMware

For this post, I decided to be product based and create a P2V – V2V auto provision script for Veeam Agent for Windows and VMWare. To use this script, you will need Powershell version 3 and PowerCLI from Vmware as well as create a folder in C called C:\Scripts. You can run this script on any system on your network that has access to the systems that you want to recover and has access to your vCenter or ESXi host. You will also need to make a few modifications of the script to make it work in your environment. I will highlight those as we go along in this post.

You will need to create a baseline Veeam Recovery media ISO for Vmware in oder to perform a bare metal boot with the proper drivers for network and boot disk.

This only creates the C (OS) drive and sets that up to recover. For additional drives I would use the Veeam Backup and Replication GUI to export the disks as .vmdk files into the VM datastore folder and add them using Vmware GUI.

The script has 4 parameters that get passed to it, the server name/IP that you want to recover that is running the Veeam Agent for Windows, vCenter/host name or IP, user to log in to vCenter, and password for the user. To execute the script looks like this:

If using IP, you will need to use the single quote.

Here is the script:

Param($agent,$vserver,$vuser,$vpass)

# Collect the info from WMI
$computerSystem = get-wmiobject Win32_ComputerSystem -ComputerName $agent
$computerOS = get-wmiobject Win32_OperatingSystem -ComputerName $agent
$computerCPU = get-wmiobject Win32_ComputerSystem -ComputerName $agent | select NumberOfLogicalProcessors
$computerHDD = Get-WmiObject Win32_LogicalDisk -Filter drivetype=3 -ComputerName $agent

#Build the CSV file
$csvObject = New-Object PSObject -property @{
'PCName' = $computerSystem.Name
'RAM' = "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB).tostring("N0")
'HDDcapC' = "{0:N2}" -f ($computerHDD.Size[0]/1GB).tostring("N0")
'CPU' = $computerCPU.NumberOfLogicalProcessors
'OS' = $computerOS.caption
}

#Export the fields you want from above in the specified order
$csvObject | Select PCName, Ram, CPU, HDDcapC | Export-Csv 'system-info.csv' -NoTypeInformation

#Connect to VMware environment
Connect-VIServer -Server $vserver -User $vuser -Password $vpass

$vms = Import-CSV "C:\Scripts\system-info.csv"

#Assign Variables
$Disk = $vms.HDDcapC
$vCPU = $vms.CPU
$Memory = $vms.RAM
$VMName = $vms.PCName

#Where the VM gets built
New-VM -Name $VMName -MemoryGB $Memory -NumCpu $vCPU -DiskGB $Disk -CD -GuestID windows8Server64Guest -Datastore 'data'

#Change Network Adapter type
Get-VM $VMName | Get-NetworkAdapter | Set-NetworkAdapter -Type VMXNet3 -Confirm:$False

#Mount Veeam ISO boot image

$isopath = "[data] ISO\RecoveryMediaWin2012r2.iso"

Get-VM $VMName | Get-CDDrive | Set-CDDrive -ISOPath $isopath -StartConnected:$true -Confirm:$false

 

You can use the Powershell editor or Notepad++ to modify the code

You need to modify the following:

Line 33

-Guest ID windows8Server64Guest is server 2012

Windows7Server64Guest is server 2008r2

-Datastore to the datastore you want to place this VM onto

Line 40

$isopath “[data] ISO\RecoveryMediaWin2012r2.iso”

Need to change this to the datastore, folder, and ISO image that has your recovery media stored

 

Once the script runs, the VM will show in Vmware console and should just need to be powered on.

When the VM boots up, it will show the Veeam bare metal recovery wizard:

On my system I had to load the network drivers, click on the network icon in the lower right:

 

Click Load network adapter driver:

Click Install driver

Once installed you will have the ability to set the network properties if needed:

After network is setup, you can click the Bare Metal Recovery

Choose Network storage

Choose either Shared folder, Veeam Backup, or Veeam Cloud Connect

Put in the link, server name, IP, and login credentials as needed

Choose the backup for the selected system

Choose the restore point

For restore mode, I would suggest the System volumes only or manual restore to match the OS drive to the drive in the newly created VM

The VM will restore and then reboot. You may choose to power it off at this point in order to add additional drives or modify the VM for advanced settings.

Leave a Comment