PowerShell script exchange
Post Reply
hagepat
Veeam ProPartner
Posts: 15
Liked: never
Joined: Aug 31, 2010 1:17 pm
Contact:

PowerShell script veeam backup files to tape

Post by hagepat »

Hi all,

I have a problem with my powershell script writing veeam backup files to tape software.
If the job completes with status "success" then scripts starts and writes to tape. But if the job status is "warning" then nothing happens.
Can somebody helps me with that because I no powershell expert.

Here's my script:

# Remoting must be enabled on the BackupExec Server
# And user must have access to complete task on Veeam and BE

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

$veeamJobName = "test"
$backupExecJob = "veeam2tape"
$backupExecSvr = "MGMT01"
$backupExecPath = "C:\Program Files\Symantec\Backup Exec"

if ((Get-VBRJob | ?{$_.Name -eq $veeamJobName}).GetLastResult() -eq "Success") {
$latestOib = Get-VBRBackup | ?{$_.JobName -eq $veeamJobName} | Get-VBRRestorePoint | Sort CreationTime -Descending | Select -First 1
$latestOib
$storage = $latestOib.GetStorage()
$storage.FilePath

$file = Get-Item $storage.FilePath
if ($file.Attributes -band ([System.IO.FileAttributes]::Archive)) {
Invoke-Command -ComputerName $backupExecSvr -ScriptBlock {
param (
[PSObject]$storage,
[PsObject]$file,
[String]$backupExecJob,
[String]$backupExecPath
)

& "$backupExecPath\bemcmd.exe" -o2 -j:$backupExecJob -s:$storage.FilePath -m Tapes-Weekdays -r -w
$file.Attributes = 'Archive'
} -ArgumentList $storage, $file, $backupExecJob, $backupExecPath
}
}

Kind regards,

Patrick Hagen
pizzim13
Enthusiast
Posts: 94
Liked: 6 times
Joined: Apr 21, 2011 7:37 pm
Contact:

Re: PowerShell script veeam backup files to tape

Post by pizzim13 »

Pat,
Your issue is with line

Code: Select all

if ((Get-VBRJob | ?{$_.Name -eq $veeamJobName}).GetLastResult() -eq "Success") {
This line is only true when GetLastResult() equals "Success". It should look like

Code: Select all

if (Get-VBRJob -name $veeamJobName | Where-Object {$_.getlastresult() -eq "Success" -or $_.getlastresult() -eq "Warning"})
rhnb
Enthusiast
Posts: 81
Liked: 2 times
Joined: Jan 27, 2010 2:25 pm
Full Name: Allan Nelson
Contact:

Re: PowerShell script veeam backup files to tape

Post by rhnb »

Or you could use...

if ((Get-VBRJob | ?{$_.Name -eq $veeamJobName}).GetLastResult() -ne "Failed") {
...
pizzim13
Enthusiast
Posts: 94
Liked: 6 times
Joined: Apr 21, 2011 7:37 pm
Contact:

Re: PowerShell script veeam backup files to tape

Post by pizzim13 »

rhnb wrote:Or you could use...

if ((Get-VBRJob | ?{$_.Name -eq $veeamJobName}).GetLastResult() -ne "Failed") {
...
This will retrieve jobs that are currently running, which have a .getlastresult() of "None"
rhnb
Enthusiast
Posts: 81
Liked: 2 times
Joined: Jan 27, 2010 2:25 pm
Full Name: Allan Nelson
Contact:

Re: PowerShell script veeam backup files to tape

Post by rhnb »

But only for the job matching $veeamJobName, and as it's a post job script running for that job, ie the jobs finished, it'll retrieve the results that haven't failed won't it?
It seems to be working fine for me and I've been using it for several months.

I take your point that if it's NOT running as a post-job script ie running independently then yes, it would return a 'currently running' result.
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests