How to Run Powershell Commands Automatically

In order to run Powershell commands before and after backup tasks, use the corresponding fields in the Options tab. The

C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe C:\scripts\myscript.ps1

Check the external utility and enter the above path as shown below:

powershell

 

The command may also be passed as an argument, like this: C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe -Command {enter commands here}

Important

Please make sure the script does not require user input under any circumstances because that would lead to the script blocking the backup task indefinitely. That’s because the script runs without a window and is hence invisible to the user logged on. In addition, note that the script runs a local system user, or whatever user is configured to run BackupChain Service. The privileges of Local System are different from your personal Windows login and may cause scripts to fail. It also makes sense to use a separate logging mechanism for your script calls so that you can track their function. It’s also recommended to use the exit code as a signal to BackupChain as to whether the script succeeded. BackupChain will log errors if the ‘check exit code’ option is checked and the code doesn’t match the expected value.

Another hint: it’s not a good idea to use exit code 0 for success, which unfortunately is a standard. That’s because if the script engine crashes completely, the returned code is also 0. A crashing script would therefore return 0 and be interpreted as success. To prevent this scenario, simply use a non-zero exit code value as success in your scripts and batch files.