I need to run a powershell script after job which one will be doing sth like that:
- check status of backup (Success/Warning/Failed)
- if status is Success -> create file (log) in specific location and send e-mail notification
- if status is Warning or Failed -> send e-mail notification
Unfortunately when I run my ps script manually from Veeam PS Console everything works well, but when I add script (cmd) to my backup job nothing happen (job -> storage -> advanced -> advanced -> Run the following script after the job)
My powershell script look like that:
Code: Select all
asnp VeeamPSSnapin
$backuplog="C:\scriptsreport\SUCCESS.log"
$Job = Get-VBRJob -name "VMs_afters"
$Error.Clear()
function SendEmail($To, $From, $Subject, $Body, $attachment, $smtpServer)
{
Send-MailMessage -To $To -From $From -Subject $Subject -Body $Body -SmtpServer $smtpServer
}
$emailto=tom.mach@xc.local”
$emailfrom=”veeamserver@xc.local”
$emailserver="mail.xc.local"
Get-VBRJob -name "VMs_afters"
if($job.GetLastresult() -eq "Success")
{
remove-item "$backuplog" -Force -Recurse
Write-Output ("$(get-date -f yyyyMMdd_hhmmss)") | Out-File "$backuplog" -Append
SendEmail -To "$emailto" -From "$emailfrom" -Subject "VMs_afters Success" -Body "The backup has Success!" -smtpServer "$emailserver"
break
}
if($job.GetLastresult() -eq "Failed")
{
remove-item "$backuplog" -Force -Recurse
SendEmail -To "$emailto" -From "$emailfrom" -Subject "VMs_afters Failed" -Body "The backup has Failed!" -smtpServer "$emailserver"
break
}
if($job.GetLastresult() -eq "Warning")
{
remove-item "$backuplog" -Force -Recurse
SendEmail -To "$emailto" -From "$emailfrom" -Subject "VMs_afters Warning" -Body "The backup has Warning!" -smtpServer "$emailserver"
break
}
Code: Select all
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -Noninteractive -File "C:\Scripts\vmsafters.ps1"
Thanks Tom