PowerShell script exchange
Post Reply
Neelakantan
Influencer
Posts: 14
Liked: never
Joined: May 20, 2024 3:12 pm
Full Name: Neelakantan K
Contact:

Post-job script terminated with error code 1

Post by Neelakantan »

Below code is part of post-job script.

Code: Select all

$parentPid = (Get-WmiObject Win32_Process -Filter "processid='$scriptPid'").parentprocessid.ToString()

$parentCmd = (Get-WmiObject Win32_Process -Filter "processid='$parentPid'").CommandLine

$parentCmdArgs = $parentCmd.Replace('" "','","').Replace('"','').Split(',')

$currentJobSessionGUID = $parentCmdArgs[-1]

$currentJobSession = [Veeam.Backup.Core.CBackupSession]::GetByOriginalSessionId($currentJobSessionGUID) | Select-Object -Last 1
Transcript has below error:

>> TerminatingError(): "Unable to find type [Veeam.Backup.Core.CBackupSession]."
**********************

When i run directly in the powershell terminal on the same system, it works.

Code: Select all

PS C:\Scripts> $session=[Veeam.Backup.Core.CBackupSession]::GetByOriginalSessionId("c0f80ec7-1294-4d8b-8003-c50c4dc69e3b") | Select-Object -Last 1
PS C:\Scripts> $session

Job Name             State      Start Time             End Time               Result
--------             -----      ----------             --------               ------
Backup Job 20 (In... Stopped    5/28/2024 6:41:28 AM   5/28/2024 6:42:32 AM   Warning


PS C:\Scripts>
Could some help identify the issue and suggest the solution to this issue?

Thanks & regards,
Neelakantan K.
david.domask
Veeam Software
Posts: 2113
Liked: 509 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Post-job script terminated with error code 1

Post by david.domask »

Hi Neelakantan,

$currentJobSession = [Veeam.Backup.Core.CBackupSession]::GetByOriginalSessionId($currentJobSessionGUID) | Select-Object -Last 1

Very likely it's the bolded part that is failing; this is .NET Reflection, and .NET Reflection is not supported for use. There are some nuances to use .NET Reflection and it's best to avoid it whenever possible as the internal .NET Methods can and will change from release to release and are not meant for use like this.

If you want to check the session, use Get-VBRSession with the -Id parameter and pass the ID you're parsing out to that.
David Domask | Product Management: Principal Analyst
Neelakantan
Influencer
Posts: 14
Liked: never
Joined: May 20, 2024 3:12 pm
Full Name: Neelakantan K
Contact:

Re: Post-job script terminated with error code 1

Post by Neelakantan »

Tried your suggestion David.Domask

Code: Select all

$currentJobSession = Get-VBRSession -Id $currentJobSessionGUID
#$currentJobSession = [Veeam.Backup.Core.CBackupSession]::GetByOriginalSessionId($currentJobSessionGUID) | Select-Object -Last 1
Now getting this below error

>> TerminatingError(): "The term 'Get-VBRSession' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."
**********************

Full output

Code: Select all

Transcript started, output file is C:\Scripts\scriptlog.txt
C:\Windows\system32\config\systemprofile\transcript.txt
10600
C:\Program Files\Veeam\Backup and Replication\Backup\Veeam.Backup.Manager.exe
startbackupjob
owner=[vbsvc]
Normal
d39cc9cd-7c4f-4858-b32f-01ab0b4dfa44
7dfac394-310b-4b9a-9607-1f74dfee05a4
7dfac394-310b-4b9a-9607-1f74dfee05a4
>> TerminatingError(): "The term 'Get-VBRSession' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."
**********************

From terminal

Code: Select all

PS C:\Scripts> Get-VBRSession -Id c0f80ec7-1294-4d8b-8003-c50c4dc69e3b


Progress     : 100
RunManually  : True
Log          : {Id: 239505, Usn: 1294589, Title: Job finished with warning at 5/28/2024 6:42:32 AM , Cookie: , Description: , Time: 5/28/2024 6:42:32 AM,
               StartTime: 5/28/2024 6:42:32 AM, Status: Warning, Id: 239504, Usn: 1294584, Title: Primary bottleneck: Proxy, Cookie: , Description: , Time:
               5/28/2024 6:42:32 AM, StartTime: 5/28/2024 6:42:32 AM, Status: Succeeded, Id: 239503, Usn: 1294583, Title: Load: Source 0% > Proxy 2% >
               Network 0% > Target 0%, Cookie: , Description: , Time: 5/28/2024 6:42:32 AM, StartTime: 5/28/2024 6:42:32 AM, Status: Succeeded, Id: 239502,
               Usn: 1294582, Title: Post-job script terminated with exit code 1, Cookie: , Description: , Time: 5/28/2024 6:42:32 AM, StartTime: 5/28/2024
               6:42:31 AM, Status: Warning...}
CreationTime : 5/28/2024 6:41:28 AM
EndTime      : 5/28/2024 6:42:32 AM
JobId        : d39cc9cd-7c4f-4858-b32f-01ab0b4dfa44
Result       : Warning
State        : Stopped
Id           : c0f80ec7-1294-4d8b-8003-c50c4dc69e3b



PS C:\Scripts>
david.domask
Veeam Software
Posts: 2113
Liked: 509 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Post-job script terminated with error code 1

Post by david.domask »

Just to confirm, you're importing the Veeam Powershell module correct?

Add as a first line:

Import-Module Veeam.Backup.Powershell
David Domask | Product Management: Principal Analyst
Neelakantan
Influencer
Posts: 14
Liked: never
Joined: May 20, 2024 3:12 pm
Full Name: Neelakantan K
Contact:

Re: Post-job script terminated with error code 1

Post by Neelakantan »

No David.Domask.

I was of the assumption that, the post-job script runs in the context of the job manager process, all those things will be setup automatically.

Seems to be that was the issue, i have added that line.

Thanks and appreciate you quick response.
david.domask
Veeam Software
Posts: 2113
Liked: 509 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Post-job script terminated with error code 1

Post by david.domask » 1 person likes this post

Hi Neelakantan,

Glad to hear that it worked, thank you for confirming and glad I could assist.

I can understand your assumption here, but when you use pre/post job scripts (and pre-freeze/post-thaw), Veeam does not do _anything_ to the script or the execution environment; Veeam simply executes the script using the native host methodology (e.g., for Powershell it's just the call operator, for bash scripts we just pass the script to the shell, etc), meaning that if you don't tell the shell what it needs, it won't find it. But Veeam does not touch or alter the script or the execution environment, it just sends the command to execute the script "as-is".
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest