Pre-Job Script - BAT/Powershell and waiting

PowerShell script exchange

Pre-Job Script - BAT/Powershell and waiting

Veeam Logoby mongie » Mon Oct 03, 2016 9:52 pm

I'm trying to schedule a tape library inventory to run prior to my weekly tape backup. I've done this via the pre-job script funcitonality.

Problem is, while I know how to make powershell wait for the inventory before closing, I don't know how to get the batch file to respect that powershell is still running...

Powershell is...

Code: Select all
Add-PSSnapin -Name VeeamPSSnapin
Get-VBRTapeLibrary | Start-VBRTapeInventory -Wait


Batch File is...

Code: Select all
@ECHO OFF
Powershell.exe -ExecutionPolicy ByPass -File "C:\Program Files (x86)\Veeam\runVBRInventory.ps1"
EXIT



Any suggestions on...

a) how to run a powershell file as the pre job script?
b) how to get the batch file to run until the inventory has finished?


Thanks
mongie
Expert
 
Posts: 149
Liked: 23 times
Joined: Mon May 16, 2011 4:00 am
Location: Brisbane, Australia
Full Name: Alex Macaronis

Re: Pre-Job Script - BAT/Powershell and waiting

Veeam Logoby tsightler » Tue Oct 04, 2016 12:20 am

You can run a Powershell script directly (without a batch file) using syntax similar to this in the pre/post-script settings:

Code: Select all
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -file "C:\Program Files (x86)\Veeam\runVBRInventory.ps1"


I guess I haven't tried it with spaces + quotes, but I'd think it would work just fine, but I usually just stick my scripts in C:\Scripts to keep the path short and provide a standard location.

Worst case you should be able to edit the batch to use start like:

Code: Select all
@ECHO OFF
start /wait Powershell.exe -ExecutionPolicy ByPass -File "C:\Program Files (x86)\Veeam\runVBRInventory.ps1"
EXIT
tsightler
Veeam Software
 
Posts: 4768
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Pre-Job Script - BAT/Powershell and waiting

Veeam Logoby mongie » Sun Oct 09, 2016 9:30 pm

Thanks for the suggestion, unfortunately both methods still don't work. I also changed the path of the scripts as you suggested with no luck.
mongie
Expert
 
Posts: 149
Liked: 23 times
Joined: Mon May 16, 2011 4:00 am
Location: Brisbane, Australia
Full Name: Alex Macaronis

Re: Pre-Job Script - BAT/Powershell and waiting

Veeam Logoby v.Eremin » Mon Oct 10, 2016 9:15 am

Can you elaborate on what exactly didn't work as expected? The script didn't get executed? Did it fail with some message? Did work incorrectly? Or something else? Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Pre-Job Script - BAT/Powershell and waiting

Veeam Logoby mongie » Tue Oct 11, 2016 2:25 am

1. Tape backup starts,
2. Pre-job script is marked as successful (almost immediately)
3. Inventory doesn't start (even though it does when I run the script manually).
4. Tape job continues without inventory having run.


What I want to happen is...

1. Tape Job starts
2. Pre-job script starts - tape job waits for the task to complete
3. Inventory job starts (triggered by pre-job script).
4. Inventory completes and tape job continues.
mongie
Expert
 
Posts: 149
Liked: 23 times
Joined: Mon May 16, 2011 4:00 am
Location: Brisbane, Australia
Full Name: Alex Macaronis

Re: Pre-Job Script - BAT/Powershell and waiting

Veeam Logoby mongie » Tue Oct 11, 2016 2:27 am

There are two obvious feature requests here too...

a) Ability to schedule an inventory job
b) Ability to automatically run an inventory before a tape job - via gui options.
mongie
Expert
 
Posts: 149
Liked: 23 times
Joined: Mon May 16, 2011 4:00 am
Location: Brisbane, Australia
Full Name: Alex Macaronis

Re: Pre-Job Script - BAT/Powershell and waiting

Veeam Logoby v.Eremin » Tue Oct 11, 2016 11:48 am

2. Pre-job script is marked as successful (almost immediately) 3. Inventory doesn't start (even though it does when I run the script manually).

Most likely, backup service account doesn't have sufficient permissions. Thus, the script got started, did nothing and ended.

As to the feature request, those should be better submitted on tapes subforum to draw sufficient attention.

Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Pre-Job Script - BAT/Powershell and waiting

Veeam Logoby mongie » Wed Oct 12, 2016 2:13 am

Where is the service account defined?
mongie
Expert
 
Posts: 149
Liked: 23 times
Joined: Mon May 16, 2011 4:00 am
Location: Brisbane, Australia
Full Name: Alex Macaronis

Re: Pre-Job Script - BAT/Powershell and waiting

Veeam Logoby tdewin » Wed Oct 12, 2016 6:52 am

Add this to the end of the script to see what errors come up.
Code: Select all
$error > c:\logs\errorlog.txt

Provided that c:\logs directory exists
tdewin
Veeam Software
 
Posts: 1043
Liked: 360 times
Joined: Fri Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin

Re: Pre-Job Script - BAT/Powershell and waiting

Veeam Logoby v.Eremin » Wed Oct 12, 2016 8:48 am

Where is the service account defined?

Account under which backup service is running. Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: Yahoo [Bot] and 9 guests