PowerShell script exchange
Post Reply
r.c.p.
Lurker
Posts: 2
Liked: never
Joined: Sep 20, 2020 7:10 am
Full Name: Rene Ceron Palomino
Contact:

powershell command after a job in Veeam Backup and Replication

Post by r.c.p. »

Hello,
I would like to execute the following powershell command after a job in Veeam Backup and Replication:

powershell Set-ExecutionPolicy RemoteSigned -Scope LocalMachine
start powershell.exe Remove-Item \\XNAS1\usbshare1\Backups -recurse

this saved as a bat and inserted as a script after the job, it does not show an error, but does not do this either. (executed directly as a bat it works)

What do I have to do here for this to work?

all the best
R.C.P.
david.domask
Veeam Software
Posts: 2704
Liked: 626 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: powershell command after a job in Veeam Backup and Replication

Post by david.domask »

Hi Rene,

Just to confirm you set the .bat script on this step of the Job Wizard and you can see in the job statistics window after the job runs that the post-job script ran?

Keep in mind this note on the same User Guide page:
To run the script, Veeam Backup & Replication uses the Service Account under which the Veeam Backup Service is running.
Is it possible that due to the service account in use, the script is failing? (by default it's SYSTEM account, so you may need to use psexec.exe to start a powershell session as SYSTEM account)
David Domask | Product Management: Principal Analyst
r.c.p.
Lurker
Posts: 2
Liked: never
Joined: Sep 20, 2020 7:10 am
Full Name: Rene Ceron Palomino
Contact:

Re: powershell command after a job in Veeam Backup and Replication

Post by r.c.p. »

Hello David,
unfortunately that doesn't help me. I have tried a few variants but nothing has worked.
Can you please be more specific?
All the best
R.C.P.
david.domask
Veeam Software
Posts: 2704
Liked: 626 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: powershell command after a job in Veeam Backup and Replication

Post by david.domask »

Unfortunately there's not much to comment on based on just the above.

1. Can you confirm that it works when you run the same script under a SYSTEM shell with psexec?
2. Does the job show that it's running the post-job script successfully?
3. What specifically is not working? It looks like your tool just unmaps a network share, am I correct that the share stays mapped?
4. Can you share more details on that SMB share? Is it mapped or how is it presented/connected? I'm guessing the goal is some sort of air-gapping by disconnecting the SMB share after backups, but how the SMB share is presented to Windows is important.

The fact that it's an SMB share you're trying to remove is why I think it's about accounts -- I'm guessing it's mapped but maybe not, but point is that SMB sessions are user local, so if the script runs as another account, then likely SYSTEM account cannot remove it since it was connected by another user.

I would check the above troubleshooting steps and add some logging to your script (print the $error[0] message for example to a file somewhere after each command); Veeam does not alter the script in any way during execution, it's just passed to the OS to execute as it should, the only part that might be an issue is the account that launches it. I do not insist it's the account, but based on available info, right now my thoughts are about user account.
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 48 guests