PowerShell script exchange
Post Reply
dellock6
Veeam Software
Posts: 6137
Liked: 1928 times
Joined: Jul 26, 2009 3:39 pm
Full Name: Luca Dell'Oca
Location: Varese, Italy
Contact:

Change a parameter to several jobs at once

Post by dellock6 »

Hi all,
since I'm a total noob in powershell and I can only modify scripts made from others :oops: , I need some help on this: I created a script to modify the VM notes attributes like this:

Code: Select all

$job = Get-VBRJob -Name MyJob
$opt = $job.GetOptions()
$opt.ViSourceOptions.VmAttributeName = "Backup"
$opt.ViSourceOptions.SetResultsToVmNotes = $true
$job.SetOptions($opt)
How can I read every job in the Veeam Server, select only backup jobs, and change this parameter to all of them?

Thanks!
Luca.
Luca Dell'Oca
Principal EMEA Cloud Architect @ Veeam Software

@dellock6
https://www.virtualtothecore.com/
vExpert 2011 -> 2022
Veeam VMCE #1
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Change a parameter to several jobs at once

Post by Sethbartlett » 2 people like this post

Code: Select all

Get-VBRJob | ?{$_.IsBackup} | %{$opt = $_.Options; $opt.ViSourceOptions.VmAttributeName = "Backup"; $opt.ViSourceOptions.SetResultsToVmNotes = $true;$_.SetOptions($opt)}
That is the very "powershelly" way to do it, I could make it prettier, but it works nicely :)
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
dellock6
Veeam Software
Posts: 6137
Liked: 1928 times
Joined: Jul 26, 2009 3:39 pm
Full Name: Luca Dell'Oca
Location: Varese, Italy
Contact:

Re: Change a parameter to several jobs at once

Post by dellock6 »

I am at level 1 of powershell, that is copy others' scripts and try to modify them so every improved version seems like magic to me :)

I can supposed reading at the code (?{$_.IsBackup}) this one you wrote parses all backup jobs, right?

Thanks Seth!!!
Luca Dell'Oca
Principal EMEA Cloud Architect @ Veeam Software

@dellock6
https://www.virtualtothecore.com/
vExpert 2011 -> 2022
Veeam VMCE #1
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Change a parameter to several jobs at once

Post by Sethbartlett »

Yeah, for example:

Code: Select all

Get-VBRJob | Where-Object {$_.IsBackup}
I short hand everything I can, Jobs have a method called "IsBackup" and it returns true/false. If you just said if($Job.IsBackup) it assumes you mean true.
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests