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.
-
- Service Provider
- Posts: 10
- Liked: never
- Joined: Sep 21, 2022 3:33 pm
- Contact:
-
- Veeam Software
- Posts: 2590
- Liked: 606 times
- Joined: Jun 28, 2016 12:12 pm
- Contact:
Re: Check Running Jobs
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:
This is very loose code but the general idea should work for you. Basically just let Powershell do date-math for you 
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
}
}

David Domask | Product Management: Principal Analyst
-
- Service Provider
- Posts: 10
- Liked: never
- Joined: Sep 21, 2022 3:33 pm
- Contact:
Re: Check Running Jobs
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):
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
}
}
-
- Veeam Software
- Posts: 2590
- Liked: 606 times
- Joined: Jun 28, 2016 12:12 pm
- Contact:
Re: Check Running Jobs
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
Who is online
Users browsing this forum: No registered users and 31 guests