PowerShell script exchange
Post Reply
dryan0506
Novice
Posts: 3
Liked: never
Joined: Mar 18, 2021 5:39 pm
Full Name: Dan Ryan
Contact:

Copy list of VMs from one job to another

Post by dryan0506 »

Hello All,

I have a highly tailored job (I'll call it job A). Somehow the list of VMs is not correct (clerical errors I'm guessing). the list of VMs I need for the job exists in job B. However because of all the settings I've configured on job A, I would prefer to copy the list of VMs of job B to it, rather than clone job B and reconfigure all of the job settings. So let's say the following:

JobA contains:
Server1
Server2
Server4


JobB contains the list of VMs I want to be included in JobA:

Server2
Server6
Server7



I am having trouble with the syntax, or am not providing what the cmdlets are looking for. I have tried a few variants of the following:

Code: Select all

get-vbrjobobject -Job "JobB" | Add-VBRViJobObject -job "JobA" -Entities $_ -Force 

Code: Select all

get-vbrjobobject -Job "JobB" | foreach-object {Add-VBRViJobObject -job "JobA" -Entities $_} 

Code: Select all

get-vbrjobobject -Job "JobB" | Select-Object Name | ForEach-Object {find-vbrvientity -name $_ | Add-VBRViJobObject -Job "JobA" -Entities $_} 

Code: Select all

get-vbrjobobject -Job "App Servers_Daily" | Select-Object Name -OutVariable vms
Add-VBRViJobObject -Job "App Servers_Monthly" -Entities $vms

Code: Select all

$servers=get-vbrserver -name *
Find-VBRViEntity -server $servers -VMsAndTemplates | select Name
ForEach-Object {Add-VBRViJobObject -Job "JobA" -Entities $_}
I'm not sure what the Add-VBRViJobObject cmdlet is looking for but I can't quite make it happy.

Does anyone have any suggestions for this?
dryan0506
Novice
Posts: 3
Liked: never
Joined: Mar 18, 2021 5:39 pm
Full Name: Dan Ryan
Contact:

Re: Copy list of VMs from one job to another

Post by dryan0506 »

Adding another failed attempt where I tried to put the list of VMs into an array:

Code: Select all

$a=@(Get-VBRJobObject -Job "JobB")
Add-VBRViJobObject -Job "JobA" -Entities $a
which resulted in the following: + CategoryInfo : InvalidArgument: (:) [Add-VBRViJobObject], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Veeam.Backup.PowerShell.Cmdlets.AddVBRViJobObject

Out of curiosity, i tried to simply add a VM to the job and still got a failure, so i'm pretty sure I just don't know what the command is looking for, but the Veeam KB is a bit sparse on examples for this cmdlet:

Code: Select all

Add-VBRViJobObject -Job "JobA" -Entities VM01
Add-VBRViJobObject : Cannot bind parameter 'Entities'. Cannot convert the "VM01" value of type "System.String" to
type "Veeam.Backup.Core.Infrastructure.IViItem".
At line:1 char:57
+ Add-VBRViJobObject -Job "JobA" -Entities VM01
+                                                         ~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Add-VBRViJobObject], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Veeam.Backup.PowerShell.Cmdlets.AddVBRViJobObject
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Copy list of VMs from one job to another

Post by oleg.feoktistov » 1 person likes this post

Hi Dan,

The deal is quite simple here. Get-VBRJobObject returns objects of CObjectInJob class, whereas -Entities parameter in Add-VBRViJobObject cmdlet expects objects of IViItem class. You were very close with your 3rd option. Here is the code corrected:

Code: Select all

 get-vbrjobobject -Job $job | ForEach-Object { find-vbrvientity -name $_.Name  | Add-VBRViJobObject -Job $job2 } 
- You needed to call Name on $_ explicitly, since you parse vbr entities by string, not the whole object.
- You didn't need -Entities parameter for Add-VBRViJobObject if you already passed an object to the pipeline.

Thanks,
Oleg
dryan0506
Novice
Posts: 3
Liked: never
Joined: Mar 18, 2021 5:39 pm
Full Name: Dan Ryan
Contact:

Re: Copy list of VMs from one job to another

Post by dryan0506 »

Oleg,

This did the trick. Thank you for clarifying what classes the commands were looking for. I think that was the missing piece. I appreciate your help!
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Copy list of VMs from one job to another

Post by oleg.feoktistov »

Glad to assist, Dan!
sfaits
Enthusiast
Posts: 35
Liked: 7 times
Joined: Apr 07, 2017 7:08 pm
Contact:

Re: Copy list of VMs from one job to another

Post by sfaits »

Oleg, I am attempting to move vms from one job to another as well but when I use the above command that worked for dryan0506 I am getting warnings messages about WARNING: Object reference not set to an instance of an object, WARNING: One or more errors occurred.
The new job is not populated.

Thank you.
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests