PowerShell script exchange
Post Reply
bctak25
Lurker
Posts: 1
Liked: never
Joined: Jun 29, 2025 5:46 pm
Full Name: Brandon Carroll
Contact:

Stop job pre-job script

Post by bctak25 »

Morning,

I have a pre-job powershell script that runs several checks on the server. Is there a way to abort the calling job depending on the powershell exit code or another method?

Is there a way to pass a message to the warning email instead of "Pre-job script terminated with exit code 1" ?

Thank you
david.domask
Veeam Software
Posts: 2823
Liked: 645 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Stop job pre-job script

Post by david.domask »

Hi bctak25, welcome to the forums.

> Is there a way to abort the calling job depending on the powershell exit code or another method?

No direct way, but you can use native powershell methods to find the calling job:

Code: Select all

$ScriptPID = Get-WMIObject win32_process | Where-Object {$_.ProcessID -eq $PID}
$ParentProc = Get-WMIObject win32_process | Where-Object {$_.ProcessID -eq $ScriptPID.ParentProcessId}
$JobID = $ParentProc.CommandLine.Split()[7].Trim('"')
$Job = Get-VBRJob | Where-Object {$_.id -eq $JobID}
From there I suppose you can pass the job to Stop-VBRJob to stop the job.

> Is there a way to pass a message to the warning email instead of "Pre-job script terminated with exit code 1" ?

Not within Veeam. Veeam simply passes the provided script and has the host OS execute it, and then Veeam responds based on the exit code. You can exit your script with a custom exit code in Powershell to pass some information in the exit code.
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest