Just a bit of background here. We run a large hyper-v estate (100+ hosts holding 100+ VM's each), and we have a constant maintenance schedule where all the VM's are shared nothing live migrated around the estate and the hosts have firmware/drivers and windows updates performed on them.
When a VM is moved between the hosts it breaks the Veeam job, and we fix it by going to the job in the GUI, removing the VM and then reading it. This can be time-consuming as you can imagine.
What I am trying to achieve is to automate this process. When our migration script comes across a VM that is being backed up by one or more Veeam jobs, it moves the VM then removes and re-adds it to all those jobs.
this is what I have :
Code: Select all
Add-PSSnapin VeeamPSSnapin
function change-VBRVMhost
{
param(
[string]$VMname
)
#Find the job ID's for the jobs the VM is currently a member of
$Jobids = ($JobsIds = Get-VBRJob | Get-VBRJobObject | where name -Like $VMname ).Jobid
#use those ID's to find the names of those jobs
foreach ($joBiD IN $Jobids)
{
$JobName += (get-vbrjob | where id -like $Jobids).name
}
#remove the VM from all backup
$ObjectToRemove = Get-VBRJob | Get-VBRJobObject | where name -Like $VMname
Remove-VBRJobObject -Objects $ObjectToRemove
#re-add the VM to the jobs
foreach ($jobname in $jobnames)
{
Find-VBRHvEntity -Name $VMname | Add-VBRHvJobObject -Job $jobname
}
}