Standalone backup agent for Microsoft Windows servers and workstations (formerly Veeam Endpoint Backup FREE)
feelgoodeule
Influencer
Posts: 19
Liked: 14 times
Joined: Jul 28, 2009 12:28 pm
Full Name: Michael

Here it is: Powershell script to add VEB-EMails

Post by feelgoodeule » 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!

Dima P.
Product Manager
Posts: 10643
Liked: 874 times
Joined: Feb 04, 2013 2:07 pm
Full Name: Dmitry Popov
Location: Prague
Contact:

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

Post by Dima P. » 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

feelgoodeule
Influencer
Posts: 19
Liked: 14 times
Joined: Jul 28, 2009 12:28 pm
Full Name: Michael

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

Post by feelgoodeule » Apr 20, 2015 12:50 pm

Thanks.
Just noticed: please take out "-Attachments body.txt" from the Send-MailMessage - Line. Then it works.
Michael

Dima P.
Product Manager
Posts: 10643
Liked: 874 times
Joined: Feb 04, 2013 2:07 pm
Full Name: Dmitry Popov
Location: Prague
Contact:

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

Post by Dima P. » 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.

feelgoodeule
Influencer
Posts: 19
Liked: 14 times
Joined: Jul 28, 2009 12:28 pm
Full Name: Michael

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

Post by feelgoodeule » Apr 20, 2015 1:19 pm

Dima,

Didn't rerun it again, but looks ok like this. Thank you.

theflash89
Novice
Posts: 6
Liked: 2 times
Joined: Apr 15, 2015 2:46 am
Full Name: Brett Brownderville
Contact:

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

Post by theflash89 » Apr 22, 2015 2:18 pm

Is there a way to set it to only email on failures?

Wocka
Enthusiast
Posts: 37
Liked: 3 times
Joined: Oct 01, 2014 12:04 am
Full Name: Warwick Ferguson
Contact:

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

Post by Wocka » Apr 22, 2015 11:31 pm

Thank you for this.
Fantastic script and working well.

feelgoodeule
Influencer
Posts: 19
Liked: 14 times
Joined: Jul 28, 2009 12:28 pm
Full Name: Michael

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

Post by feelgoodeule » 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.

lrosa
Influencer
Posts: 15
Liked: 2 times
Joined: Dec 11, 2012 9:11 pm
Full Name: Luigi Rosa
Location: Italy
Contact:

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

Post by lrosa » 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"
}

feelgoodeule
Influencer
Posts: 19
Liked: 14 times
Joined: Jul 28, 2009 12:28 pm
Full Name: Michael

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

Post by feelgoodeule » 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..."

Mike Resseler
Product Manager
Posts: 5776
Liked: 621 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

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

Post by Mike Resseler » 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

Deansbkk
Novice
Posts: 7
Liked: never
Joined: Feb 23, 2010 6:13 am
Full Name: Dean S
Contact:

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

Post by Deansbkk » 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?

Mike Resseler
Product Manager
Posts: 5776
Liked: 621 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

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

Post by Mike Resseler » 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
Product Manager
Posts: 5776
Liked: 621 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

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

Post by Mike Resseler » 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...

Deansbkk
Novice
Posts: 7
Liked: never
Joined: Feb 23, 2010 6:13 am
Full Name: Dean S
Contact:

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

Post by Deansbkk » 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

Mike Resseler
Product Manager
Posts: 5776
Liked: 621 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

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

Post by Mike Resseler » May 15, 2015 5:01 am

Dean,

The update functionality didn't work in the beta in RC versions hence the reason why it didn't tell you to update. I certainly advise you to uninstall and update because the GA version fixes lots of things and we don't support the beta or RC versions anymore.

BUT, before you do, it is important to know a few things:

1. You will need to start over again. We made significant changes between RC and GA. Uninstall the RC (control panel, add/remove programs) and re-install the GA version. That means you need to recreate your backup job and the recovery ISO? There are no worries about the USB hard drive registration though. When creating the job again, just point it to that HDD and it will be used again.

2. It will become a whole new backup chain. As said, the changes are too big to continue to use the old chain.

3. You won't be able to recover from your old backups anymore. If you still think that will be necessary, I advise you to keep the backups (until the X days are over), keep the installer for the RC somewhere safe, and if necessary, install RC on a VM (then you can use that one to recover whatever you want from the old backups)

Cheers

Mike

gmele
Enthusiast
Posts: 27
Liked: never
Joined: Apr 30, 2015 9:10 pm
Full Name: Mele Giuseppe
Contact:

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

Post by gmele » May 15, 2015 12:08 pm

Hi Michael,

great script! I implemented it and it works fine. As we don't have a local SMTP mail server I created a google account for my client and integrated the use of the sendEmail-v156 utility.

Now we know if the backup has run and whether it was successful or not.

Thank you,

Joe

ominfo
Novice
Posts: 7
Liked: never
Joined: May 15, 2015 4:45 pm
Full Name: Olivier Martin
Contact:

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

Post by ominfo » May 15, 2015 4:56 pm

When i test the script manually with powershell ... it's work.

But when i'm trying using with event monitoring in the task scheduled... i'm not receiving any email. What i'm doing wrong i'm my tasks settings ?

REgards

Mike Resseler
Product Manager
Posts: 5776
Liked: 621 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

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

Post by Mike Resseler » May 16, 2015 5:27 am

Hi Oliver,

Can you describe us (be as detailed as possible) how you have created your scheduled task? Maybe we can figure out what's wrong

Thanks

Mike

ominfo
Novice
Posts: 7
Liked: never
Joined: May 15, 2015 4:45 pm
Full Name: Olivier Martin
Contact:

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

Post by ominfo » May 16, 2015 12:05 pm

In General :
Run whether user is logged on or not
Run with highest privileges
Password stored

Trigger
On an event
Basic
Log : Veeam Endpoint Backup
Source : Veeam Endpoint Backup
Enabled

Action :
Start a program c:\veeamscript.ps1

Settings and conditions by default

Mike Resseler
Product Manager
Posts: 5776
Liked: 621 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

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

Post by Mike Resseler » May 18, 2015 8:12 am

Olivier,

I don't see anything wrong here... did you trigger the task manually once? I have heard that it needs to triggered (not the script, but the scheduled task itself) before it actually does something. (No idea why, but that is what he heard...)

Let me know

Mike

JaxIsland7575
Veeam Vanguard
Posts: 388
Liked: 105 times
Joined: Apr 27, 2015 1:59 pm
Full Name: Ryan Jacksland
Location: NY, USA
Contact:

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

Post by JaxIsland7575 » May 18, 2015 1:19 pm

I have had situations where I created a task and tried to run it manually and it fails. I have had to populate the "Start In:" field to get it to work. So if my script path is: "C:\scripts\Veeam.ps1" then the Start In field is: "C:\scripts"

Just a thought and hope it helps.
VMCE v9

Deansbkk
Novice
Posts: 7
Liked: never
Joined: Feb 23, 2010 6:13 am
Full Name: Dean S
Contact:

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

Post by Deansbkk » May 19, 2015 12:57 am

Mike,

Please note that I did install the GA version, am currently running the GA version, and it's the GA version that is producing these old EventID's. I can't remember for sure if I uninstalled the RC version or just installed GA over top of RC (think the latter). Anyhow it looks like I need to uninstall my current GA and then reinstall to fix this.

Regarding the USB hard drive registration, the issue is we rotate 4 hard drives (1 drive per week). On the weekly change will I have to manually register the hard drives again (if yes I realize it will be on the first rotation only) or is there a way I can avoid this (backup/restore the current hard drive registrations).

Thanks again.

Dean

Mike Resseler
Product Manager
Posts: 5776
Liked: 621 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

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

Post by Mike Resseler » May 19, 2015 4:35 am

Dean,

I'm not sure, but I believe you will need to register them again...

Mike

ominfo
Novice
Posts: 7
Liked: never
Joined: May 15, 2015 4:45 pm
Full Name: Olivier Martin
Contact:

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

Post by ominfo » May 19, 2015 6:50 pm

I have added the "Start In" infos... no more success

I have tried to end and restart the task...

The result is (0x41306) does that mean something for you ?

Mike Resseler
Product Manager
Posts: 5776
Liked: 621 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

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

Post by Mike Resseler » May 19, 2015 7:01 pm

Not sure why it is happening but it means: The last run of the task was terminated by the user

ominfo
Novice
Posts: 7
Liked: never
Joined: May 15, 2015 4:45 pm
Full Name: Olivier Martin
Contact:

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

Post by ominfo » May 19, 2015 7:03 pm

Ok... so this is only a confirmation that i ended the task erlier...

So because i'm not receiving any alert email... it's means to me that the trigger is not working... but why ? :(

Mike Resseler
Product Manager
Posts: 5776
Liked: 621 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

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

Post by Mike Resseler » May 19, 2015 7:08 pm

Good question...

Can you try to delete the scheduled task and recreate it? After recreating, run it manually once

(Sorry, kind of getting out of ideas here...)

JaxIsland7575
Veeam Vanguard
Posts: 388
Liked: 105 times
Joined: Apr 27, 2015 1:59 pm
Full Name: Ryan Jacksland
Location: NY, USA
Contact:

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

Post by JaxIsland7575 » May 22, 2015 4:19 pm

I am stuck with this as well. I can manually run the PowerShell script with no problem and I get the email. When I use task scheduler the job runs and stays running until I manually end it with no email being sent. I have created the job a couple times with the same result. I have it running as an admin with highest privileges. Any ideas from the gallery would be appreciated!
VMCE v9

JaxIsland7575
Veeam Vanguard
Posts: 388
Liked: 105 times
Joined: Apr 27, 2015 1:59 pm
Full Name: Ryan Jacksland
Location: NY, USA
Contact:

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

Post by JaxIsland7575 » May 22, 2015 5:03 pm

As a follow up, I went to Event Viewer and right click the 109 Event and said to Attach Task to This Event and let it create the task that way. Double checked settings and same result as if I manually create the task with it just sitting and running.
VMCE v9

Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests