PowerShell script exchange
Post Reply
Tbindloss
Lurker
Posts: 1
Liked: never
Joined: Sep 23, 2019 2:20 pm
Full Name: Tom Bindloss
Contact:

Backup Script error code - 196608

Post by Tbindloss »

I'm attempting to run a Powershell script to stop a service before Veeam does a backup and to then re-enable it once the backup is complete.
I've written the script and tested it to confirm it works, I've then created the .bat script to call the powershell script which works. However, when I run the Veeam backup I get the following error -
"Pre-Job script terminated with exit code - 196608" and "Post-Job script terminated with exit code - 196608".

Does anyone have any suggestions?

Here are copies of the code I'm using (With some data blanked out)

.BAT Pre script

Code: Select all

@ECHO OFF
powershell.exe -ExecutionPolicy ByPass -File "\\SERVERNAME\c$\Scripts\PS\SCRIPTNAME.ps1"
exit
Pre-Backup Powershell

Code: Select all

$ResServices = "SERVICES TO RESTART NAME'
$C = 'SERVERNAME'
$S = 'SERVICE TO STOP NAME'
foreach ($Service in $ResServices){
           Get-Service -ComputerName $C -Name $Service | Stop-Service -Force 
           Get-Service -ComputerName $C -Name $Service | Start-Service}

Get-Service -ComputerName $C -Name $S | Stop-Service -Force
    Start-Sleep -Seconds 10
$status = Get-Service -ComputerName $C -Name $S| Select Status -ExpandProperty Status
if($status -eq 'Stopped'){echo exit}
else{Get-Service -ComputerName $C -Name $S | Stop-Service -Force
     exit
     }
veremin
Product Manager
Posts: 20406
Liked: 2299 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Backup Script error code - 196608

Post by veremin »

Can you set execution policy to remotelysigned and re-run the script? Thanks!
chris.arceneaux
VeeaMVP
Posts: 695
Liked: 374 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: Backup Script error code - 196608

Post by chris.arceneaux »

Hi Tom,

Welcome to the Veeam forums!

Best to have the PowerShell script locally. Veeam KB2183 has good info surrounding this as well as a parameter you're missing: -noprofile

On another note, the WaitForStatus method would allow you to reduce several lines of your script.

Snippet to replace:

Code: Select all

Get-Service -ComputerName $C -Name $S | Stop-Service -Force
    Start-Sleep -Seconds 10
$status = Get-Service -ComputerName $C -Name $S| Select Status -ExpandProperty Status
if($status -eq 'Stopped'){echo exit}
else{
    Get-Service -ComputerName $C -Name $S | Stop-Service -Force
    exit
}
WaitForStatus method applied:

Code: Select all

$svc = Get-Service -ComputerName $C -Name $S
$svc.Stop()
$svc.WaitForStatus('Stopped','00:00:010')
exit
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests