PowerShell script exchange
Post Reply
pesos
Expert
Posts: 205
Liked: 17 times
Joined: Nov 12, 2014 9:40 am
Full Name: John Johnson
Contact:

can't get powershell pre/post scripts to work

Post by pesos »

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

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

Post by veremin »

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.
pesos
Expert
Posts: 205
Liked: 17 times
Joined: Nov 12, 2014 9:40 am
Full Name: John Johnson
Contact:

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

Post by pesos »

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
Expert
Posts: 205
Liked: 17 times
Joined: Nov 12, 2014 9:40 am
Full Name: John Johnson
Contact:

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

Post by pesos »

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
Expert
Posts: 205
Liked: 17 times
Joined: Nov 12, 2014 9:40 am
Full Name: John Johnson
Contact:

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

Post by pesos »

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

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

Post by veremin »

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.
lrhazi
Enthusiast
Posts: 94
Liked: 3 times
Joined: Jan 03, 2017 8:15 pm
Full Name: Mohamed Lrhazi
Contact:

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

Post by lrhazi »

So PowerShell scripts are currently not supported, right? One should use .bat ?
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin »

They are supported, but cannot be executed alone, without reference to executable file, such as PowerShell.exe. Thanks.
mdxyz
Service Provider
Posts: 26
Liked: 2 times
Joined: Jan 05, 2018 3:19 am
Contact:

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

Post by mdxyz »

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.
Ioannis.T
Enthusiast
Posts: 32
Liked: 2 times
Joined: Dec 14, 2017 1:49 pm
Full Name: Ioannis Tsitsiklis
Contact:

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

Post by Ioannis.T »

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
lrhazi
Enthusiast
Posts: 94
Liked: 3 times
Joined: Jan 03, 2017 8:15 pm
Full Name: Mohamed Lrhazi
Contact:

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

Post by lrhazi »

Thanks a lot Ioannis.
mdxyz
Service Provider
Posts: 26
Liked: 2 times
Joined: Jan 05, 2018 3:19 am
Contact:

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

Post by mdxyz »

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.
Ioannis.T
Enthusiast
Posts: 32
Liked: 2 times
Joined: Dec 14, 2017 1:49 pm
Full Name: Ioannis Tsitsiklis
Contact:

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

Post by Ioannis.T »

Hi mdxyz,

Indeed that worked like a charm.
Simply indeed
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests