Here it is: Powershell script to add VEB-EMails

Backup agent for Microsoft Windows servers and workstations (formerly Veeam Endpoint Backup FREE)

Here it is: Powershell script to add VEB-EMails

Veeam Logoby feelgoodeule » Mon Apr 20, 2015 12:29 pm 9 people like this post

EMails on success/failure has been an often requested feature, VEB is not a viable way to backup servers, so I wrote this script (Tested on W7 and W2k8 R2 SP2)
Copy the Script to the computer running VEB.
Create a Task, triggered by an event of the source "Veeam Endpoint Backup"
Make sure that the event is really happening, I wondered a lot that the task was "ready" but no mails came, although VEB finished and the script was ok. I had to "execute" it once.


Code: Select all
###########################################################
# Edit this part:
$youremailserver=    "YourServerName"
$sender      =   "YourSenderAddress"
$recipient   =   "YourRecipient"
###########################################################

# Put most info into the body of the email:
$TimeGenerated   =    get-eventlog "Veeam Endpoint Backup" -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-List -property TimeGenerated | out-string
$Source      =   get-eventlog "Veeam Endpoint Backup" -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-List -property Source | out-string
$EntryType   =   get-eventlog "Veeam Endpoint Backup" -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-List -property EntryType | out-string
$Message   =   get-eventlog "Veeam Endpoint Backup" -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-List -property Message | out-string
$InstanceID   =   get-eventlog "Veeam Endpoint Backup" -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-List -property InstanceID| out-string
$Body      =   " $TimeGenerated Instance-ID: $InstanceID $Message "


# Determine the subject according to the result of the backup:
if ($Message.contains("Success")) {
   $subject = "EndpointBackup finished with Success."
} elseif ($InstanceID.contains("110")) {
   $subject = "EndpointBackup started."
} else {   
   $subject = "EndpointBackup finished but NO SUCCESS!! Check Body for details."
}


# Send the email using the powershell object (replace with e.g. blat.exe for older powershell-Versions)
if ($InstanceID.contains("110") -Or  $InstanceID.contains("190")) {
   Send-MailMessage -To $recipient -Subject $subject -From $sender -Body $body -SmtpServer $Youremailserver
} else {
   write-host "I don't want messages on 10010 and 10050 Restorepoint-creation or -remove Emails, skip those"
}


write-host "Script finished with -$instanceID- as the last event-ID"



I hope that someone finds the code useful, although I would really appreciate if it would be a feature of VEB instead of this peace of additional artwork.
Thanks so far for this useful free tool!
feelgoodeule
Influencer
 
Posts: 18
Liked: 14 times
Joined: Tue Jul 28, 2009 12:28 pm
Full Name: Michael

Re: Here it is: Powershell script to add VEB-EMails

Veeam Logoby Dima P. » Mon Apr 20, 2015 12:47 pm

Hello Michael,
Thank you for your time – the script is awesome! You should have added yourself as an author to the comments at the beginning of the script :D
Dima P.
Veeam Software
 
Posts: 5953
Liked: 421 times
Joined: Mon Feb 04, 2013 2:07 pm
Location: SPb
Full Name: Dmitry Popov

Re: Here it is: Powershell script to add VEB-EMails

Veeam Logoby feelgoodeule » Mon Apr 20, 2015 12:50 pm

Thanks.
Just noticed: please take out "-Attachments body.txt" from the Send-MailMessage - Line. Then it works.
Michael
feelgoodeule
Influencer
 
Posts: 18
Liked: 14 times
Joined: Tue Jul 28, 2009 12:28 pm
Full Name: Michael

Re: Here it is: Powershell script to add VEB-EMails

Veeam Logoby Dima P. » Mon Apr 20, 2015 1:00 pm

Michael,
I've corrected the script according to your post, please, check if it’s ok now? Hopefully, I’ll be able to test it myself later today.
Dima P.
Veeam Software
 
Posts: 5953
Liked: 421 times
Joined: Mon Feb 04, 2013 2:07 pm
Location: SPb
Full Name: Dmitry Popov

Re: Here it is: Powershell script to add VEB-EMails

Veeam Logoby feelgoodeule » Mon Apr 20, 2015 1:19 pm

Dima,

Didn't rerun it again, but looks ok like this. Thank you.
feelgoodeule
Influencer
 
Posts: 18
Liked: 14 times
Joined: Tue Jul 28, 2009 12:28 pm
Full Name: Michael

Re: Here it is: Powershell script to add VEB-EMails

Veeam Logoby theflash89 » Wed Apr 22, 2015 2:18 pm

Is there a way to set it to only email on failures?
theflash89
Novice
 
Posts: 6
Liked: 2 times
Joined: Wed Apr 15, 2015 2:46 am
Full Name: Brett Brownderville

Re: Here it is: Powershell script to add VEB-EMails

Veeam Logoby Wocka » Wed Apr 22, 2015 11:31 pm

Thank you for this.
Fantastic script and working well.
Wocka
Enthusiast
 
Posts: 26
Liked: 2 times
Joined: Wed Oct 01, 2014 12:04 am
Full Name: Warwick Ferguson

Re: Here it is: Powershell script to add VEB-EMails

Veeam Logoby feelgoodeule » Thu Apr 23, 2015 5:59 am

Hi theflash89,

Yes, you can set it to "errors only" by changing the parameter "-entrytype Information, Warning, Error" to "-entrytype Error"
I didn't tried it out, but that's the way it's supposed to work.

Keep in mind that if you do it like this you don't get any messages if the backup didn't take place, maybe because the service is not running or whatever.
feelgoodeule
Influencer
 
Posts: 18
Liked: 14 times
Joined: Tue Jul 28, 2009 12:28 pm
Full Name: Michael

Re: Here it is: Powershell script to add VEB-EMails

Veeam Logoby lrosa » Tue May 05, 2015 3:51 am 2 people like this post

Hi,
thank you for this useful script.

Here's a patch of the parsing section to produce a subject with the same style as the default Veeam B&R mail report and the hostname of the Windows host, in case you set this script on multiple PCs/Servers


Code: Select all
# Determine the subject according to the result of the backup:
$hostname = hostname
if ($Message.contains("Success")) {
   $subject = "[Success] Endpoint Backup $hostname"
} elseif ($InstanceID.contains("110")) {
   $subject = "[Started] Endpoint Backup $hostname"
} else {   
   $subject = "[Failed] Endpoint Backup $hostname failed"
}
lrosa
Influencer
 
Posts: 15
Liked: 2 times
Joined: Tue Dec 11, 2012 9:11 pm
Location: Italy
Full Name: Luigi Rosa

Re: Here it is: Powershell script to add VEB-EMails

Veeam Logoby feelgoodeule » Fri May 08, 2015 1:59 pm 1 person likes this post

Thanks for the patch. Looks nicer that way, more like B&R-Mails, better for Outlook rules .

I experienced a strange behaviour on our different Mailservers:

Depending on their configuration, you have to set -usessl in the send-message-line:

Code: Select all
Send-MailMessage -To $recipient -Subject $subject -From $sender -Body $body -SmtpServer $Youremailserver -usessl


Try this if you have your server authorised to send mails but still having those "for your smtp-Server a secure connection is needed..."
feelgoodeule
Influencer
 
Posts: 18
Liked: 14 times
Joined: Tue Jul 28, 2009 12:28 pm
Full Name: Michael

Re: Here it is: Powershell script to add VEB-EMails

Veeam Logoby Mike Resseler » Fri May 08, 2015 3:03 pm

Michael,

Thanks for the addition. This is indeed a known one depending on the config of your mail server. But I am sure that many will have that config so your additional line is very much appreciated

Cheers

Mike
Mike Resseler
Veeam Software
 
Posts: 2997
Liked: 354 times
Joined: Fri Feb 08, 2013 3:08 pm
Location: Belgium, the land of the fries, the beer, the chocolate and the diamonds...
Full Name: Mike Resseler

Re: Here it is: Powershell script to add VEB-EMails

Veeam Logoby Deansbkk » Thu May 14, 2015 7:18 am

Thanks for the script. However it's not completely working for us as our VEB installation generates an EventID 0 at exactly the same time stamp as the EventID 190. Due to this EventID 0 the task scheduler won't launch the task for the EventID 190 because another instance is already running. I set task scheduler to run a new event in parallel but it stills misses the event. The end result is that the script doesn't run for the EventID 190 so we don't receive an email.

Another odd thing is that our EventID for 'Backup Job Started" is 23050 (not 110).

As a workaround I set the get-eventlog parameter to retrieve the last 2 events (get-eventlog "Veeam Endpoint Backup" -newest 2) which works but it clutters up the notification

Has anyone else experienced this?

Does anyone else have a EventID 0 for every VEB job? Or an EventID of 23050?
Deansbkk
Novice
 
Posts: 5
Liked: never
Joined: Tue Feb 23, 2010 6:13 am
Full Name: Dean S

Re: Here it is: Powershell script to add VEB-EMails

Veeam Logoby Mike Resseler » Thu May 14, 2015 8:40 am

Hi Dean,

I don't have those. Event ID 23050 is normally seen with the Veeam Management Pack and not with VEBF. Can you pass us 2 screenshots of your event viewer, with the tree and one located on the event 0 and one on evet 23050?

Thanks

Mike
Mike Resseler
Veeam Software
 
Posts: 2997
Liked: 354 times
Joined: Fri Feb 08, 2013 3:08 pm
Location: Belgium, the land of the fries, the beer, the chocolate and the diamonds...
Full Name: Mike Resseler

Re: Here it is: Powershell script to add VEB-EMails

Veeam Logoby Mike Resseler » Thu May 14, 2015 8:42 am

Dean,

Also, I just remembered that 23050, the 0 and 190 were used either in the beta or the RC... Which version are you running? Go to Control Panel, update and see what your version is...
Mike Resseler
Veeam Software
 
Posts: 2997
Liked: 354 times
Joined: Fri Feb 08, 2013 3:08 pm
Location: Belgium, the land of the fries, the beer, the chocolate and the diamonds...
Full Name: Mike Resseler

Re: Here it is: Powershell script to add VEB-EMails

Veeam Logoby Deansbkk » Fri May 15, 2015 12:47 am

Hi Mike,

This server was running the RC but then I upgraded (didn't uninstall RC first) to v1.0.0.1921. I see v1.0.0.1954 is now available (looking at Veeam website download section) yet the update feature in VEB advises it's up to date (separate issue).

I'm happy to uninstall this installation and re-install as I presume that will fix the EventID's. Before I uninstall/re-install do you know how I can backup/restore the configuration (most important would be the USB hard drive registrations)?

Do you know if a re-install will affect the existing backup chains?

Many thanks...Dean
Deansbkk
Novice
 
Posts: 5
Liked: never
Joined: Tue Feb 23, 2010 6:13 am
Full Name: Dean S

Next

Return to Veeam Agent for Windows



Who is online

Users browsing this forum: No registered users and 10 guests