PowerShell script exchange
Post Reply
SRedlin
Influencer
Posts: 10
Liked: 1 time
Joined: Sep 23, 2016 10:20 am
Full Name: Stefan Redlin
Contact:

Run After Job

Post by SRedlin »

Hey Folks,

In my code i loop thru all jobs and all vmnames and want to add the information when the job is scheduled after a specific job?
How can i archive this goal? :)


Code: Select all

$jobs = Get-VBRJob | ?{$_.JobType -eq "Backup"}
foreach ($job in $jobs) {
    
    foreach ($vm in $job.GetObjectsInJob()) {
        $jobOptions = New-Object PSObject
        $jobOptions | Add-Member -MemberType NoteProperty -Name "VMName" -value $vm.name
        $jobOptions | Add-Member -MemberType NoteProperty -Name "JobName" -value $job.name

        $Schedule = $Null
        $Schedule = Get-VBRJobScheduleOptions -Job $job

        if($test.ScheduleOptions.OptionsScheduleAfterJob.IsEnabled -eq $True){

        $jobOptions | Add-Member -MemberType NoteProperty -Name "Run After" -Value "Run After" -ErrorAction SilentlyContinue

}
veremin
Product Manager
Posts: 20282
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Run After Job

Post by veremin » 2 people like this post

You can find a name of parent job, using the following script:

Code: Select all

ASnp VeeamPSSNapin
$Childjob = Get-VBRJob -name "Name of child job"
Get-VBRJob | where {$_.id -eq $Childjob.Info.ParentScheduleId} | select name
Thanks.
reaperhammer
Service Provider
Posts: 27
Liked: 9 times
Joined: Aug 18, 2016 7:59 pm
Full Name: Will S
Contact:

Re: Run After Job

Post by reaperhammer » 2 people like this post

There is a new property with the same info in 9.5u3 'PreviousJobIdInScheduleChain'

Code: Select all

#Method1
$jobs=get-vbrjob
foreach ($job in $jobs){
$job | select name,@{N='RunAfter';E={($jobs | ?{$_.id -eq $Job.PreviousJobIdInScheduleChain}).Name}}
}
#Method2
$jobs=get-vbrjob
foreach ($job in $jobs){
$job | select name,@{N='RunAfter';E={($jobs | ?{$_.id -eq $Job.info.ParentScheduleId}).Name}}
}
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests