Running a PowerShell script from a BAT fails when using pre-freeze/post-thaw or pre-job/post job scripts

KB ID: 2183
Product: Veeam Backup & Replication
Version: 9.x
Published: 2016-10-24
Last Modified: 2020-08-13
Get weekly article updates
By subscribing, you are agreeing to have your personal information managed in accordance with the terms of Veeam's Privacy Notice.

Cheers for trusting us with the spot in your mailbox!

Now you’re less likely to miss what’s been brewing in our knowledge base with this weekly digest

error icon

Oops! Something went wrong.

Please try again later.

Challenge

To provide a bat file template for calling PowerShell scripts to prevent Script execution errors

Cause

PowerShell execution policy and UAC/Windows permissions issues may be causing script call to fail

Solution

The following template .bat file may be used to call PowerShell scripts.


@ECHO OFF
REM edit the example line bellow to set  PowerShellScriptPath  to the PowerShell script path on the guest VM being backed up
SET PowerShellScriptPath="C:\Windows\Scripts\script.ps1”   
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%PowerShellScriptPath%""' -Verb RunAs}";

 

More information

When you run a pre-freeze/post-thaw script from a BAT file, the BAT file is stored on the Veeam Backup Server, and will be copied to a temporary location on the guest when the job runs.  The Powershell script will need to be located on the guest that is being backed up and that you want the script to run on.  The path for PowerShellScriptPath variable needs to be the exact path and file name on the guest.    
 
When you are running pre or post job scripts, both the BAT file and the PowerShell script will be launched from the VeeamBackup server independent of the guest.
 
For error reporting you can add “>> C:\TEMP\Err_ps.txt” to the end of each action line on the PowerShell script, or “>> C:\TEMP\Err_cmd.txt” to the end of each  action line in the BAT file to get error reporting output. 
Send Article Feedback
To report a typo on this page, highlight the typo with your mouse and press CTRL + Enter.

Spelling error in text

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Thank you!

Thank you!

Your feedback has been received and will be reviewed.

Oops! Something went wrong.

Please try again later.

KB Feedback/Suggestion

This form is only for KB Feedback/Suggestions, if you need help with the software open a support case

By submitting, you are agreeing to have your personal information managed in accordance with the terms of Veeam's Privacy Notice.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Verify your email to continue your product download
We've sent a verification code to:
  • Incorrect verification code. Please try again.
An email with a verification code was just sent to
Didn't receive the code? Click to resend in sec
Didn't receive the code? Click to resend
Thank you!

Thank you!

Your feedback has been received and will be reviewed.

error icon

Oops! Something went wrong.

Please try again later.