PowerShell script exchange
Post Reply
mongie
Expert
Posts: 152
Liked: 24 times
Joined: May 16, 2011 4:00 am
Full Name: Alex Macaronis
Location: Brisbane, Australia
Contact:

Pre-Job Script - BAT/Powershell and waiting

Post by mongie »

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
tsightler
VP, Product Management
Posts: 6009
Liked: 2843 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

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

Post by tsightler »

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
mongie
Expert
Posts: 152
Liked: 24 times
Joined: May 16, 2011 4:00 am
Full Name: Alex Macaronis
Location: Brisbane, Australia
Contact:

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

Post by mongie »

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.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin »

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.
mongie
Expert
Posts: 152
Liked: 24 times
Joined: May 16, 2011 4:00 am
Full Name: Alex Macaronis
Location: Brisbane, Australia
Contact:

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

Post by mongie »

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: 152
Liked: 24 times
Joined: May 16, 2011 4:00 am
Full Name: Alex Macaronis
Location: Brisbane, Australia
Contact:

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

Post by mongie »

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.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin »

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.
mongie
Expert
Posts: 152
Liked: 24 times
Joined: May 16, 2011 4:00 am
Full Name: Alex Macaronis
Location: Brisbane, Australia
Contact:

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

Post by mongie »

Where is the service account defined?
tdewin
Veeam Software
Posts: 1775
Liked: 646 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

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

Post by tdewin »

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
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin »

Where is the service account defined?
Account under which backup service is running. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests