PowerShell script exchange
Post Reply
DanCasan
Service Provider
Posts: 6
Liked: never
Joined: Sep 21, 2022 3:33 pm
Contact:

Check Running Jobs

Post by DanCasan »

Hi all, i'm trying to find a way to check and, if needed, notify if a backup job is running for more than x hours.
I found several command that output the status of a job, the start, etc etc, but I can't get the output I'm looking for.
Is there someone who has already had this need?

Thank you.
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Check Running Jobs

Post by david.domask » 1 person likes this post

Hi @DanCasan,

There isn't a cmdlet that directly reports on the long running job, but it should be easy enough to write a script that has a quick check based on the Get-Date comparison to the CreationTime property returned by Get-VBRJob and Get-VBRBackupSession.

A simple way with unsupported method would be:

Code: Select all

$jobs = Get-VBRJob
$currDate = Get-Date
Foreach($j in $jobs){
    $lastSess = $j.FindLastSession()
    if(($currDate - $lastSess.Creationtime).Hours -gt $N){
          Some action like maybe send an email
     }
}
This is very loose code but the general idea should work for you. Basically just let Powershell do date-math for you :)
David Domask | Product Management: Principal Analyst
DanCasan
Service Provider
Posts: 6
Liked: never
Joined: Sep 21, 2022 3:33 pm
Contact:

Re: Check Running Jobs

Post by DanCasan »

Hi david, thank you for the tip.
I started from your code and i modified it, now I have a PS1 that check running jobs for more than 10 hours (applicable to Backup, Replica, Backup copy):

Code: Select all

$jobs = Get-VBRJob
Foreach($j in $jobs){
	$lastSess = $j.FindLastSession()
	if(($lastSess.State -eq "Working") -and ($lastSess.Creationtime -lt (Get-Date).AddHours(-10))){
	$lastSess.JobName + " is " + $lastSess.State >> C:\Veeam_Script\check_running.txt
    }
}
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Check Running Jobs

Post by david.domask »

Hi @DanCasan, glad you could figure it out with the hints, and thank you for sharing your resulting code ) it always helps everyone when we share knowledge :)
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 16 guests