PowerShell script exchange
Post Reply
gmorris
Enthusiast
Posts: 27
Liked: never
Joined: Jun 06, 2009 2:46 am
Full Name: Glen Morris
Contact:

Running Veeam Powershell script in Backup Job

Post by gmorris »

I would like to run a Veeam powershell script as part of the Advanced Job scripts, I have never did this before what is the best way of running them, [i.e. is there a command to call the Veeam Powershell snap-in]
Vitaliy S.
VP, Product Management
Posts: 27368
Liked: 2799 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: Running Veeam Powershell script in Backup Job

Post by Vitaliy S. »

Yes, there is a command to do that. Please see our on-line User Guide for further details > http://helpcenter.veeam.com/backup/80/powershell/
veremin
Product Manager
Posts: 20389
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Running Veeam Powershell script in Backup Job

Post by veremin »

In order to get access to VB&R specific commands you'll need to add snap-in to current PS session first.

Code: Select all

Add-PSSnapin VeeamPSSnapin
Thanks.
gmorris
Enthusiast
Posts: 27
Liked: never
Joined: Jun 06, 2009 2:46 am
Full Name: Glen Morris
Contact:

Re: Running Veeam Powershell script in Backup Job

Post by gmorris »

thanks, that works when I run the powershell script.
when I point to the Powershell script file in the Job script [script.ps1] section under Advanced I am recieving an error
The specified executable is not a valid application for this OS platform
It appears to be looking for a .bat .cmd or .exe file
veremin
Product Manager
Posts: 20389
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Running Veeam Powershell script in Backup Job

Post by veremin »

Yep, both pre and post job commands should be batch. But there is nothing preventing you from triggering PS scripts from a batch. Thanks.
nefes
Veeam Software
Posts: 649
Liked: 170 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: Running Veeam Powershell script in Backup Job

Post by nefes »

You could also use such string:

Code: Select all

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe <path to your file>.ps1
gmorris
Enthusiast
Posts: 27
Liked: never
Joined: Jun 06, 2009 2:46 am
Full Name: Glen Morris
Contact:

Re: Running Veeam Powershell script in Backup Job

Post by gmorris »

Thanks, I created the following batch file in the same folder [same name] as the PS script. it works good.

@ECHO OFF
powershell.exe -noninteractive -noprofile -Command "& '%~dpn0.ps1'"
EXIT /B %errorlevel%
gholder
Novice
Posts: 3
Liked: never
Joined: Feb 08, 2014 2:08 pm
Full Name: Gary Holder
Contact:

Re: Running Veeam Powershell script in Backup Job

Post by gholder »

-command didnt work for me...this did
@echo off
Powershell.exe set-executionpolicy remotesigned -File C:\Users\SE\Desktop\ps.ps1
chas0rde
Enthusiast
Posts: 28
Liked: 3 times
Joined: Jan 14, 2015 7:01 am
Contact:

Re: Running Veeam Powershell script in Backup Job

Post by chas0rde » 1 person likes this post

I think that powershell should be supported directly.
I don't get why it isn't. Most of Veeam is in fact PS-Scriptable.

Only for the pre/post-scripts you have to do those stupid workarounds that then cause your number of scripts to maintain to double

Please add this ;)

Best regards
Erhardt
Influencer
Posts: 18
Liked: never
Joined: Aug 23, 2013 2:25 pm
Full Name: Erhardt
Contact:

Re: Running Veeam Powershell script in Backup Job

Post by Erhardt »

gholder wrote:-command didnt work for me...this did
@echo off
Powershell.exe set-executionpolicy remotesigned -File C:\Users\SE\Desktop\ps.ps1

Had to use

Code: Select all

@ECHO OFF
Powershell.exe -ExecutionPolicy ByPass -File C:\Powershell-Script\1337script.ps1
EXIT
chas0rde wrote:I think that powershell should be supported directly.
I don't get why it isn't. Most of Veeam is in fact PS-Scriptable
Yes, fully agree with you :!:
lowlander
Service Provider
Posts: 453
Liked: 30 times
Joined: Dec 28, 2014 11:48 am
Location: The Netherlands
Contact:

Re: Running Veeam Powershell script in Backup Job

Post by lowlander » 1 person likes this post

For windows 2012 R2 is use the following oneliners on the Veeam Backup Server:

Code: Select all

c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe c:\scripts\prescript.ps1
c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe c:\scripts\postscript.ps1
works as a charm :)
chas0rde
Enthusiast
Posts: 28
Liked: 3 times
Joined: Jan 14, 2015 7:01 am
Contact:

Re: Running Veeam Powershell script in Backup Job

Post by chas0rde »

lowlander wrote:For windows 2012 R2 is use the following oneliners on the Veeam Backup Server:

Code: Select all

c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe c:\scripts\prescript.ps1
c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe c:\scripts\postscript.ps1
works as a charm :)
Do you add this oneliner as command for pre-/post-script in the Veeam config or just in a batch?
veremin
Product Manager
Posts: 20389
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Running Veeam Powershell script in Backup Job

Post by veremin »

Pre/Post job activity would be my guess, as the provided examples should work fine for them. Though, avoid using them as a pre-freeze/post-thaw scripts, since those work differently. Thanks.
chas0rde
Enthusiast
Posts: 28
Liked: 3 times
Joined: Jan 14, 2015 7:01 am
Contact:

Re: Running Veeam Powershell script in Backup Job

Post by chas0rde »

v.Eremin wrote:Though, avoid using them as a pre-freeze/post-thaw scripts, since those work differently
Yes. Pre-Freeze/Post-Thaw would only copy the batch and not find the ps1
I use network stored ps1's for that purpose and reference to the UNC path. Works and allows easier maintenance of the scripts (single location and no more copy stuff back and forth)
Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot] and 21 guests