Running Veeam Powershell script in Backup Job

PowerShell script exchange

Running Veeam Powershell script in Backup Job

Veeam Logoby gmorris » Tue Feb 17, 2015 6:47 pm

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]
gmorris
Enthusiast
 
Posts: 27
Liked: never
Joined: Sat Jun 06, 2009 2:46 am
Full Name: Glen Morris

Re: Running Veeam Powershell script in Backup Job

Veeam Logoby Vitaliy S. » Tue Feb 17, 2015 8:19 pm

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/
Vitaliy S.
Veeam Software
 
Posts: 19539
Liked: 1097 times
Joined: Mon Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov

Re: Running Veeam Powershell script in Backup Job

Veeam Logoby v.Eremin » Wed Feb 18, 2015 9:49 am

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.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 966 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Running Veeam Powershell script in Backup Job

Veeam Logoby gmorris » Wed Feb 18, 2015 9:59 pm

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
gmorris
Enthusiast
 
Posts: 27
Liked: never
Joined: Sat Jun 06, 2009 2:46 am
Full Name: Glen Morris

Re: Running Veeam Powershell script in Backup Job

Veeam Logoby v.Eremin » Thu Feb 19, 2015 12:02 pm

Yep, both pre and post job commands should be batch. But there is nothing preventing you from triggering PS scripts from a batch. Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 966 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Running Veeam Powershell script in Backup Job

Veeam Logoby nefes » Thu Feb 19, 2015 2:17 pm

You could also use such string:
Code: Select all
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe <path to your file>.ps1
nefes
Veeam Software
 
Posts: 534
Liked: 125 times
Joined: Mon Dec 10, 2012 8:44 am
Full Name: Nikita Efes

Re: Running Veeam Powershell script in Backup Job

Veeam Logoby gmorris » Tue Feb 24, 2015 3:14 pm

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%
gmorris
Enthusiast
 
Posts: 27
Liked: never
Joined: Sat Jun 06, 2009 2:46 am
Full Name: Glen Morris

Re: Running Veeam Powershell script in Backup Job

Veeam Logoby gholder » Thu Jun 18, 2015 10:21 am

-command didnt work for me...this did
@echo off
Powershell.exe set-executionpolicy remotesigned -File C:\Users\SE\Desktop\ps.ps1
gholder
Novice
 
Posts: 3
Liked: never
Joined: Sat Feb 08, 2014 2:08 pm
Full Name: Gary Holder

Re: Running Veeam Powershell script in Backup Job

Veeam Logoby chas0rde » Mon Aug 03, 2015 6:15 am 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
chas0rde
Enthusiast
 
Posts: 28
Liked: 3 times
Joined: Wed Jan 14, 2015 7:01 am

Re: Running Veeam Powershell script in Backup Job

Veeam Logoby Erhardt » Tue Aug 11, 2015 7:36 pm

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 :!:
Erhardt
Influencer
 
Posts: 18
Liked: never
Joined: Fri Aug 23, 2013 2:25 pm
Full Name: Erhardt

Re: Running Veeam Powershell script in Backup Job

Veeam Logoby lowlander » Fri May 20, 2016 7:18 am 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 :)
lowlander
Service Provider
 
Posts: 267
Liked: 20 times
Joined: Sun Dec 28, 2014 11:48 am

Re: Running Veeam Powershell script in Backup Job

Veeam Logoby chas0rde » Fri Jul 22, 2016 9:49 am

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?
chas0rde
Enthusiast
 
Posts: 28
Liked: 3 times
Joined: Wed Jan 14, 2015 7:01 am

Re: Running Veeam Powershell script in Backup Job

Veeam Logoby v.Eremin » Fri Jul 22, 2016 9:53 am

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.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 966 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Running Veeam Powershell script in Backup Job

Veeam Logoby chas0rde » Fri Jul 22, 2016 10:37 am

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)
chas0rde
Enthusiast
 
Posts: 28
Liked: 3 times
Joined: Wed Jan 14, 2015 7:01 am


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 5 guests