PowerShell script exchange
Post Reply
frankU32
Enthusiast
Posts: 36
Liked: 2 times
Joined: May 02, 2018 11:56 am
Full Name: Frank Tighe
Contact:

Remove and Re-add VM to job

Post by frankU32 »

Good morning everyone,

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
    }

}
It seems to work fine, but the last line "Find-VBRHvEntity" takes an absolute age to run, to the point where the script isn't that usable, it's taking more time than it saves. Can anyone suggest how I could improve this script at all?
veremin
Product Manager
Posts: 20282
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Remove and Re-add VM to job

Post by veremin »

Side question - how VMs are added to a backup console? Via cluster, via SCVMM, via standalone hosts (I assume, this is the case)?

If so, can you leverage one of the first two options, this way you wouldn't need any scripts to track VMs, as this would be done by backup server itself. More information on that.

Thanks.
frankU32
Enthusiast
Posts: 36
Liked: 2 times
Joined: May 02, 2018 11:56 am
Full Name: Frank Tighe
Contact:

Re: Remove and Re-add VM to job

Post by frankU32 »

They are all stand alone Hyper-v hosts
veremin
Product Manager
Posts: 20282
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Remove and Re-add VM to job

Post by veremin »

Then, scripting is your only option.

We're aware of performance issue with the said cmdlet, but cannot currently comment when the enhancements will be introduced.

Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests