PowerShell script exchange
Post Reply
Giacomo_N
Enthusiast
Posts: 93
Liked: 16 times
Joined: Feb 15, 2013 1:56 pm
Full Name: Giacomo
Location: Italy
Contact:

Shutting down Veeam after jobs complete

Post by Giacomo_N »

Hi all, I've the need to shutting down the Veeam server after all jobs complete successfully.
I've found this script into a 2012 post:

Code: Select all

PS C:\> Get-Content C:\jobs.txt | ForEach-Object {Get-VBRBackupSession | Select-
Object JobName, Result} if ((Get-VBRJob | ?{$_.Name -eq $LastJobName}).GetLastresult() -eq "Success" {shutdown.exe -s -t 1}
I've put a jobs name inside a .txt file, but not working.
Are they something new ?

Thanks
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Shutting down Veeam after jobs complete

Post by PTide » 1 person likes this post

Hi,

I would suggest to do that in a different way:

1. Schedule a script in Windows Task scheduler that would start AFTER the last job starts.
2. The script should keep retrieving job sessions with results other than finished/failed/warning constantly.
3. Once the output is empty trigger server shutdown.

I am really curious why would you need that?

Thanks!
Giacomo_N
Enthusiast
Posts: 93
Liked: 16 times
Joined: Feb 15, 2013 1:56 pm
Full Name: Giacomo
Location: Italy
Contact:

Re: Shutting down Veeam after jobs complete

Post by Giacomo_N »

Hi Ptide,

thank you for the reply, in answer to your question, I want to shutting down Veeam server to save resource during working hours.

I'm trying to play with PS scripts as you suggested, but I was never good at that :(
Following the PS example I can get the last job status with this command:

Code: Select all

PS C:\Users\administrator.FERCAD> $job = Get-VBRJob -Name "BKP-Job03"
PS C:\Users\administrator.FERCAD> Get-VBRBackupSession | Where {$_.jobId -eq $job.Id.Guid} | Sort EndTimeUTC -Descending
 | Select -First 1
Please, can you give me another small help ?


Thank you in advance
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Shutting down Veeam after jobs complete

Post by veremin »

I think there is an easier way:

1) Get jobs
2) Check if any are running, using IsRunning property or GetLastState() method
3.1) If yes, suspend script activity, using Start-Sleep cmdlet; return to step 1
3.2) If no, shutdown the server

Thanks.
Giacomo_N
Enthusiast
Posts: 93
Liked: 16 times
Joined: Feb 15, 2013 1:56 pm
Full Name: Giacomo
Location: Italy
Contact:

Re: Shutting down Veeam after jobs complete

Post by Giacomo_N »

Hi Eremin,

I'm try to find "isrunning" property, please can you give me a little more help to build the script?

Thank you
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Shutting down Veeam after jobs complete

Post by veremin »

IsRunning:

Code: Select all

Get-VBRJob | where {$_.IsRunning -eq $False}
GetLastState():

Code: Select all

Get-VBRJob | where {$_.GetlastState() -eq "Stopped"}
Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests