can't get powershell pre/post scripts to work

PowerShell script exchange

can't get powershell pre/post scripts to work

Veeam Logoby pesos » Wed Nov 16, 2016 5:59 am

support case 01977243

Hi all,

On my 9.0 server (both host and veeam server are 2012r2) I'm attempting to launch pre and post powershell scripts as part of a job. I receive this error for both scripts (they are almost identical):
Code: Select all
[16.11.2016 00:55:28] <01> Info     Running post-job script
[16.11.2016 00:55:28] <01> Info     Executing custom command 'C:\Program Files\Veeam\Backup and Replication\MoveToEH2.ps1', arguments ''
[16.11.2016 00:55:28] <01> Warning  Error running post-job: The specified executable is not a valid application for this OS platform.
[16.11.2016 00:55:28] <01> Error    The specified executable is not a valid application for this OS platform. (System.ComponentModel.Win32Exception)



I tested a script with the same command on my 9.5 server (both host and veeam server are 2016) and I get this error instead:

Code: Select all
[15.11.2016 21:51:29] <01> Info     Running pre-job script
[15.11.2016 21:51:29] <01> Info     Executing custom command [powershell.exe], arguments ["C:\Program Files\Veeam\Backup and Replication\move.ps1" ]
[15.11.2016 21:51:31] <01> Warning  Pre-job script terminated with exit code 1



Any ideas? Spoke with a late-night level 1 tech on the phone and she didn't really seem to have a firm grasp of what powershell is. All we tried was locating the script in different locations on the C drive to no avail. I had tried setting the backup service to run under my enterprise/domain admin account instead of localsystem but also no luck there...

Thanks!
pesos
Enthusiast
 
Posts: 44
Liked: 1 time
Joined: Wed Nov 12, 2014 9:40 am
Full Name: John Johnson

Re: can't get powershell pre/post scripts to work

Veeam Logoby v.Eremin » Wed Nov 16, 2016 11:32 am

It seems that you're trying to specify a script itself as a pre/post-job activity (such as "Path\Script.ps1"). Thus, the error regarding unsupported type.

Can you try to set the following construction and see whether the issue persists?

Code: Select all
powershell.exe -file -"Path\Script.ps1"


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

Re: can't get powershell pre/post scripts to work

Veeam Logoby pesos » Wed Nov 16, 2016 5:29 pm

Hi, I'm a little confused by this reply...

When I click "browse" in the area to select the pre and post scripts, the drop down options explicitly list the supported script types. In the dropdown I select Powershell and then it shows me any and all ps1 files in the folder(s) I browse to.

So if it isn't supported to have a powershell script in the field, why would the browse dialog be set up to explicitly encourage choosing and selecting them?
pesos
Enthusiast
 
Posts: 44
Liked: 1 time
Joined: Wed Nov 12, 2014 9:40 am
Full Name: John Johnson

Re: can't get powershell pre/post scripts to work

Veeam Logoby pesos » Wed Nov 16, 2016 6:57 pm

Support has said that the script is launching fine now (from c:\scripts) so it's not their problem.

I find this very poor support since the scripts work perfectly when launched manually on the backup server.

So without more information on exactly how Veeam is launching the script (under what credentials etc) it's very hard to troubleshoot.
pesos
Enthusiast
 
Posts: 44
Liked: 1 time
Joined: Wed Nov 12, 2014 9:40 am
Full Name: John Johnson

Re: can't get powershell pre/post scripts to work

Veeam Logoby pesos » Fri Nov 18, 2016 4:25 am

Pushed back on this a little and was contacted by Jeff who was fantastic.

He dug a bit and found that although powershell scripts are selectable directly, there is evidently some kind of bug that prevents them from launching properly.

We were able to get it called via a BAT file after changing the veeam backup service account to my admin user instead of localsystem.

w00t!
pesos
Enthusiast
 
Posts: 44
Liked: 1 time
Joined: Wed Nov 12, 2014 9:40 am
Full Name: John Johnson

Re: can't get powershell pre/post scripts to work

Veeam Logoby v.Eremin » Fri Nov 18, 2016 10:00 am

I agree that corresponding masks are bit misleading. The idea has been to provide convenient way to browse files with certain extensions, though, in order to make everything work the reference to application is still required (like, powershell.exe).

We're aware of confusion caused and do plan to fix down the road.

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

Re: can't get powershell pre/post scripts to work

Veeam Logoby lrhazi » Fri Dec 22, 2017 10:49 pm

So PowerShell scripts are currently not supported, right? One should use .bat ?
lrhazi
Influencer
 
Posts: 15
Liked: never
Joined: Tue Jan 03, 2017 8:15 pm
Full Name: Mohamed Lrhazi

Re: can't get powershell pre/post scripts to work

Veeam Logoby v.Eremin » Mon Dec 25, 2017 11:44 am

They are supported, but cannot be executed alone, without reference to executable file, such as PowerShell.exe. Thanks.
v.Eremin
Veeam Software
 
Posts: 14023
Liked: 1051 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: can't get powershell pre/post scripts to work

Veeam Logoby mdxyz » Wed Jan 10, 2018 9:34 am

You can also convert your posh scripts to an exe using PS2EXE. Otherwise as others have said you need to call powershell and pass it the path to your script.
mdxyz
Novice
 
Posts: 5
Liked: never
Joined: Fri Jan 05, 2018 3:19 am

Re: can't get powershell pre/post scripts to work

Veeam Logoby Ioannis.T » Fri Jan 12, 2018 10:17 pm

I can say for sure that in 9.5 U2 & U3 calling PowerShell scripts directly works fine. I spend 2 weeks testing this.
What I can also say for sure is that sometimes "post" scripts can be tricky since they are being executed as the last part of a job.
So, if the script includes something that involves the job that calls it, it may not work.
That's is both good and bad actually.
The good is that you know if the script ran or not.
The bad is that it does not run "after" the job. e.g. If the job that calls the script is Job1, and I want to run a task after a successful Job1 status that script will never run. The reason as I explained is that the script is part of the job, and hence the success or fail status of the job also depends on, if the script runs or not. So at the time of the script's execution, the job is in progress status.

I am still trying to find a way around this
Ioannis.T
Influencer
 
Posts: 11
Liked: never
Joined: Thu Dec 14, 2017 1:49 pm
Full Name: Ioannis Tsitsiklis

Re: can't get powershell pre/post scripts to work

Veeam Logoby lrhazi » Mon Jan 15, 2018 12:49 am

Thanks a lot Ioannis.
lrhazi
Influencer
 
Posts: 15
Liked: never
Joined: Tue Jan 03, 2017 8:15 pm
Full Name: Mohamed Lrhazi

Re: can't get powershell pre/post scripts to work

Veeam Logoby mdxyz » Mon Jan 15, 2018 1:08 am

Ioannis.T wrote:I can say for sure that in 9.5 U2 & U3 calling PowerShell scripts directly works fine. I spend 2 weeks testing this.
What I can also say for sure is that sometimes "post" scripts can be tricky since they are being executed as the last part of a job.
So, if the script includes something that involves the job that calls it, it may not work.
That's is both good and bad actually.
The good is that you know if the script ran or not.
The bad is that it does not run "after" the job. e.g. If the job that calls the script is Job1, and I want to run a task after a successful Job1 status that script will never run. The reason as I explained is that the script is part of the job, and hence the success or fail status of the job also depends on, if the script runs or not. So at the time of the script's execution, the job is in progress status.

I am still trying to find a way around this


Workaround is actually pretty simple, this has been working reliably for me.

Kick off your script using "cmd.exe /C start" which starts it in a new process. Then in your actual script start off with a wait, say 120 seconds to allow Veeam to properly close off the job. After that you can run whatever logic you need which queries the now completed job. I have additional code to check whether there are any pending retries to make sure it only runs when the job is finished.
mdxyz
Novice
 
Posts: 5
Liked: never
Joined: Fri Jan 05, 2018 3:19 am

Re: can't get powershell pre/post scripts to work

Veeam Logoby Ioannis.T » Thu Jan 18, 2018 2:22 pm

Hi mdxyz,

Indeed that worked like a charm.
Simply indeed
Ioannis.T
Influencer
 
Posts: 11
Liked: never
Joined: Thu Dec 14, 2017 1:49 pm
Full Name: Ioannis Tsitsiklis


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 1 guest