PowerShell script exchange
Post Reply
Manfriday
Influencer
Posts: 16
Liked: 1 time
Joined: Sep 15, 2009 6:03 pm
Full Name: Jason Morris
Contact:

Exit code 1 when executing powershell script form a backup job

Post by Manfriday »

Hi!

I am seeing warnings from my backup copy job that runs a powershell script on job completion.
its a pretty simple job:

Code: Select all

 if ( (Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue) -eq $null )
{Add-PsSnapin VeeamPSSnapIn}

[string]$veeamServer = "myserver"

# create a credential for the service account
[string]$UserName = "username"
[string]$passwordText = Get-Content "path-to-secure-file"
[SecureString]$securePwd = $passwordText | ConvertTo-SecureString
[pscredential]$credOject = New-Object System.Management.Automation.PSCredential ($UserName, $securePwd)

#connect to Veeam Server
$vbrobject = Connect-VBRServer -Server $veeamServer -Credential $credOject

#execute the repository rescan
Get-VBRBackupRepository -Name "Repository" | Sync-VBRBackupRepository | Out-Null

#disconnect from VBR server

Disconnect-VBRServer | Out-Null

Exit(0) 
When I run the script at a command line I dont see any output to the screen, but when the script runs from the job I get the Exit Code 1.

The script DOES execute properly, so I'm not sure where this exit code is coming from.
Manfriday
Influencer
Posts: 16
Liked: 1 time
Joined: Sep 15, 2009 6:03 pm
Full Name: Jason Morris
Contact:

Re: Exit code 1 when executing powershell script form a backup job

Post by Manfriday »

When I run my script from the console and I follow up with a
$LASTEXITCODE

I can confirm that I get a 0.

Not sure where Veeam is getting the 1?
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Exit code 1 when executing powershell script form a backup job

Post by oleg.feoktistov »

Hi Jason,

I tried it on a backup copy job in my lab and no warnings rendered so far. The post-job script completes successfully.
What do you get in the job log file located here?

Code: Select all

C:\ProgramData\Veeam\Backup\<BackupCopyJobName>\Job.<Name>.BackupSync.log
Thanks,
Oleg
chris.arceneaux
VeeaMVP
Posts: 695
Liked: 374 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: Exit code 1 when executing powershell script form a backup job

Post by chris.arceneaux »

Adding to what Oleg mentioned, did you make sure to encrypt the password - "path-to-secure-file" - using the same Service Account under which the Veeam Backup Service is running?

Using that method of encryption, the same account must be used to encrypt/decrypt.
Manfriday
Influencer
Posts: 16
Liked: 1 time
Joined: Sep 15, 2009 6:03 pm
Full Name: Jason Morris
Contact:

Re: Exit code 1 when executing powershell script form a backup job

Post by Manfriday »

Yes! Thanks so much Chris. That was the issue. Once I created my password file in a PowerShell window run as the service account that veeam uses, my script worked great.
chris.arceneaux
VeeaMVP
Posts: 695
Liked: 374 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: Exit code 1 when executing powershell script form a backup job

Post by chris.arceneaux »

Glad to hear! Thanks for letting us know you got things working!
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 14 guests