Change a parameter to several jobs at once

PowerShell script exchange

Change a parameter to several jobs at once

Veeam Logoby dellock6 » Thu Jun 07, 2012 10:40 pm

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
EMEA Cloud Architect @ Veeam Software

@dellock6
http://www.virtualtothecore.com
vExpert 2011-2012-2013-2014-2015-2016
Veeam VMCE #1
dellock6
Veeam Software
 
Posts: 5052
Liked: 1333 times
Joined: Sun Jul 26, 2009 3:39 pm
Location: Varese, Italy
Full Name: Luca Dell'Oca

Re: Change a parameter to several jobs at once

Veeam Logoby Sethbartlett » Mon Jun 11, 2012 3:56 am 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.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: Change a parameter to several jobs at once

Veeam Logoby dellock6 » Mon Jun 11, 2012 5:19 pm

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
EMEA Cloud Architect @ Veeam Software

@dellock6
http://www.virtualtothecore.com
vExpert 2011-2012-2013-2014-2015-2016
Veeam VMCE #1
dellock6
Veeam Software
 
Posts: 5052
Liked: 1333 times
Joined: Sun Jul 26, 2009 3:39 pm
Location: Varese, Italy
Full Name: Luca Dell'Oca

Re: Change a parameter to several jobs at once

Veeam Logoby Sethbartlett » Mon Jun 11, 2012 7:58 pm

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.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 6 guests