PowerShell script exchange
Giacomo_N
Enthusiast
Posts: 93 Liked: 16 times
Joined: Feb 15, 2013 1:56 pm
Full Name: Giacomo
Location: Italy
Contact:
Post
by Giacomo_N » Nov 30, 2018 4:31 pm
this post
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: 6583 Liked: 798 times
Joined: May 19, 2015 1:46 pm
Contact:
Post
by PTide » Nov 30, 2018 5:24 pm
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:
Post
by Giacomo_N » Dec 03, 2018 8:47 am
this post
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: 20735 Liked: 2403 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Post
by veremin » Dec 03, 2018 11:46 am
this post
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:
Post
by Giacomo_N » Dec 11, 2018 1:41 pm
this post
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: 20735 Liked: 2403 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Post
by veremin » Dec 11, 2018 1:45 pm
this post
IsRunning:
Code: Select all
Get-VBRJob | where {$_.IsRunning -eq $False}
GetLastState():
Code: Select all
Get-VBRJob | where {$_.GetlastState() -eq "Stopped"}
Thanks!
Users browsing this forum: No registered users and 12 guests