PowerShell script exchange
SRedlin
Influencer
Posts: 10 Liked: 1 time
Joined: Sep 23, 2016 10:20 am
Full Name: Stefan Redlin
Contact:
Post
by SRedlin » May 02, 2017 2:15 pm
this post
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: 20450 Liked: 2318 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:
Post
by veremin » May 02, 2017 3:00 pm
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:
Post
by reaperhammer » Jun 28, 2018 1:45 am
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}}
}
Users browsing this forum: No registered users and 4 guests