PowerShell script exchange
Post Reply
aydenguy
Lurker
Posts: 2
Liked: never
Joined: May 29, 2018 6:59 am
Full Name: Ayden Guy
Contact:

Showing how long a veeam job has been running

Post by aydenguy »

Hi there, i'm a beginner at powershell so i'm a bit stuck on what to do here.

I've created a script which shows Veeam backup status and I want to show how long a backup has been running (H:M:S) with the percentage next to it. I want to do this so we don't have to ferry back and forth between screens to see if the backup has become stuck on a percentage.

Here's the script I wrote:

Code: Select all

Add-PSSnapin VeeamPSSnapin

$body = '' "
$jobs = Get-VBRjob

foreach ($Job in $Jobs)
{
if ($Job.isRunning)
{
        
$body += "Running"
$body += " "
$body += $job.name
$body += "`n"
    }
    elseif($job.GetLastResult() -eq "None")
    {
        $body += "Disabled"
        $body += " "
        $body += $job.Name
        $body += "`n"
    }
elseif($job.GetLastResult() -ne "Success")
{
$body += $job.GetLastResult() 
$body += " "
$body += $job.Name
$body += "`n"
}
}
Any help would be appreciated since i've been scouring the forums and the internet for a few hours and i've hit a block.

Thanks
veremin
Product Manager
Posts: 20389
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Showing how long a veeam job has been running

Post by veremin »

You need to check what jobs are currently running. Then, take a current time and subtract the latest job session creation time from it. The difference should be a time job has been running.

Check this script; might give you some ideas.

Thanks.
aydenguy
Lurker
Posts: 2
Liked: never
Joined: May 29, 2018 6:59 am
Full Name: Ayden Guy
Contact:

Re: Showing how long a veeam job has been running

Post by aydenguy »

Hi again,

I'm sort of getting there I think now. I've updated my code, it's just I don't believe the output is correct at all.

Code: Select all

Add-PSSnapin VeeamPSSnapin

$body = ""
$jobs = Get-VBRjob
$date = Get-Date  
$endTime = $Job.FindLastSession().CreationTime
$timeRunning = $date - $endTime
foreach ($Job in $Jobs)
{


if ($Job.isRunning)
{
        
$body += "Running"
$body += " "
$body += $job.name
$body += " "
$body += $timeRunning
$body += "`n"
}
    elseif($job.GetLastResult() -eq "None")
    {
        $body += "Disabled"
        $body += " "
        $body += $job.Name
        $body += "`n"
    }
elseif($job.GetLastResult() -ne "Success")
{
$body += $job.GetLastResult() 
$body += " "
$body += $job.Name
$body += "`n"
}
}
echo $body
I'm getting an output of 1.11:04:22.4667856 and i'm confused at to what this is.

Thanks
tdewin
Veeam Software
Posts: 1818
Liked: 655 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

Re: Showing how long a veeam job has been running

Post by tdewin »

would 1 day 11 hours 4 minutes and 22 seconds make sense to you?

I think the format is
day.hours:minutes:seconds.microseconds(?)
veremin
Product Manager
Posts: 20389
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Showing how long a veeam job has been running

Post by veremin »

You can use totalminutes, totalhours or similar parameters to get information in whatever units you like.

Code: Select all

$RunningTime = (Get-date) - $Job.FindlastSession().CreationTime
$RunningTime.totalminutes
Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests