PowerShell script exchange
Post Reply
Marcel
Influencer
Posts: 11
Liked: 1 time
Joined: Aug 10, 2011 8:58 am
Full Name: Marcel Nobel
Contact:

PowerShell script to monitor running jobs

Post by Marcel »

Hello,

In my setup I have about 10 backup jobs. I would like to start a HP Data Protector job after the last job finishes. So ideally I would run a post job script which starts the HP Data Protector job. My problem is that when the last Veeam job is completed earlier jobs might still be running.

So I was searching the forum to see if I could find a PowerShell script providing this functionality. I couldn’t find one :) .

Ideas?

Cheers,
Gostev
Chief Product Officer
Posts: 31460
Liked: 6648 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: PowerShell script to monitor running jobs

Post by Gostev »

Marcel wrote:So I was searching the forum to see if I could find a PowerShell script providing this functionality. I couldn’t find one :)
That is strange, because I can see all the latest forum searches, and there are no relevant ones :wink:
There are many existing topics with sample scripts querying job status, just search for powershell job status

Also, you may want to check out this sample script for tape backup integration.
Marcel
Influencer
Posts: 11
Liked: 1 time
Joined: Aug 10, 2011 8:58 am
Full Name: Marcel Nobel
Contact:

Re: PowerShell script to monitor running jobs

Post by Marcel »

That is strange, because I can see all the latest forum searches, and there are no relevant ones
There are many existing topics with sample scripts querying job status, just search for powershell job status
http://tinyurl.com/44hvsg9 :P
Marcel
Influencer
Posts: 11
Liked: 1 time
Joined: Aug 10, 2011 8:58 am
Full Name: Marcel Nobel
Contact:

Re: PowerShell script to monitor running jobs

Post by Marcel »

The scipt you pointed out is not what I'm looking for.
Gostev
Chief Product Officer
Posts: 31460
Liked: 6648 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: PowerShell script to monitor running jobs

Post by Gostev »

I understand, this just for your reference, as this is what most people are using.
Regarding querying job status, just search the forum for powershell job status
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: PowerShell script to monitor running jobs

Post by Sethbartlett »

You would want to do something like the following:

Code: Select all

$Job = Get-VBRJob | ?{$_.name -eq "JobName"}
$Job.GetLastState()
You could have this in your script to cycle through all your jobs like the following:

Code: Select all

foreach ($v in (Get-VBRJob)){$v.GetLastState()}
That will cycle through all your jobs and get the latest state.
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Marcel
Influencer
Posts: 11
Liked: 1 time
Joined: Aug 10, 2011 8:58 am
Full Name: Marcel Nobel
Contact:

Re: PowerShell script to monitor running jobs

Post by Marcel »

Thank you both for the help. I'm going to write a script for this costumer. If i'm able to produce a usable script I will post it here.

Thanks,
Marcel
Influencer
Posts: 11
Liked: 1 time
Joined: Aug 10, 2011 8:58 am
Full Name: Marcel Nobel
Contact:

Re: PowerShell script to monitor running jobs

Post by Marcel »

This is the script i'm testing now. Seems to be working for me.

Code: Select all

Add-PSSnapin Veeampssnapin
$JobActive=0
Do {
foreach ($v in (Get-VBRJob))
{
	$JobStatus = ($v.GetLastState())
	If ($JobStatus -notlike "Stopped"){$JobActive ++}
}}
while($JobActive -notlike "0")
#Insert backup command here
Would be a nice feature in the next release. A little checkbox in the post job activity screen "Only run when no jobs are running" would be enough for me. :D

Edit: I would be realy nice to have a job chaining feature in the next release. @Veeam please see this as a feature request.
Gostev
Chief Product Officer
Posts: 31460
Liked: 6648 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: PowerShell script to monitor running jobs

Post by Gostev »

Why do you need job chaining, Marcel?
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: PowerShell script to monitor running jobs

Post by Sethbartlett »

We do have "job chaining" so to speak. If you go to properties -> Next until the last page that says "Summary". You can grab the command line string and place it into the "post job" script for another job. From here, one job will kick off another.
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Marcel
Influencer
Posts: 11
Liked: 1 time
Joined: Aug 10, 2011 8:58 am
Full Name: Marcel Nobel
Contact:

Re: PowerShell script to monitor running jobs

Post by Marcel » 1 person likes this post

Ik know the command is in the summary tab, thanks.

I think it would be nice to have chaining in the interface because not all customers are able to create en maintain (powershell) scripts.
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: PowerShell script to monitor running jobs

Post by Sethbartlett »

Chaining jobs together with the command in the summary tab doesn't require any powershell. If you want to make sure other jobs aren't running or special things, then that currently requires powershell:)
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Gostev
Chief Product Officer
Posts: 31460
Liked: 6648 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: PowerShell script to monitor running jobs

Post by Gostev »

Marcel, my question is more about why do you need the ability to chain. I would like to understand your use case behind it. Thanks.
Marcel
Influencer
Posts: 11
Liked: 1 time
Joined: Aug 10, 2011 8:58 am
Full Name: Marcel Nobel
Contact:

Re: PowerShell script to monitor running jobs

Post by Marcel »

Anton, maybe chaining isn’t the right word. Let’s call it grouping. Grouping lets us put multiple jobs in a group. One feature of a group is the ability to set a post command after all the jobs in this group are done (regardless of the result).

Another nice feature of a group would be to set (besides a post job command) some of the settings for all the jobs in the group for example VSS credentials, Restore points etc.

You might say “There is a job for, you don’t need group”. When we install Veeam at large customers (200+ vm’s) we need to create multiple jobs. In the past we created one job for a lot of VM’s. We noticed this is not always the best way to go. One reason for this is file corruption. In the past we had file corruption a few times. The only way to resolve this was to create a new full backup. This can take a long time when we are talking about more the 15TB.

I hope the above is clear.
Gostev
Chief Product Officer
Posts: 31460
Liked: 6648 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: PowerShell script to monitor running jobs

Post by Gostev »

Marcel, thanks for the detailed explanation.
Marcel
Influencer
Posts: 11
Liked: 1 time
Joined: Aug 10, 2011 8:58 am
Full Name: Marcel Nobel
Contact:

Re: PowerShell script to monitor running jobs

Post by Marcel »

Additional question. Is it possible to set a working directory for the post job command?
Gostev
Chief Product Officer
Posts: 31460
Liked: 6648 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: PowerShell script to monitor running jobs

Post by Gostev »

If it is BAT file, then just put in the first line:

Code: Select all

cd /d C:\Directory
Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests