Here it is: Powershell script to add VEB-EMails

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

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

Veeam Logoby JaxIsland7575 » Fri May 22, 2015 5:33 pm 1 person likes this post

I have found the solution for me. When creating the task I used these options, any option not specifically listed was disabled or not selected:
Security Options:
-Run whether user is logged in or not
-Run with highest privileges

Triggers:
Basic Settings
-Log: Veeam Endpoint Backup
-Source: Veeam Endpoint Backup
-EventID: 190
-I used 190 because I didn't want email when it started, just an email on how it finished, by default you can leave this blank
-Stop task if it runs longer: 30 minutes
-Enabled

Actions:
Start a Program
Settings:
Program/Script: C:\windows\system32\windowspowershell\v1.0\powershell.exe
Add arugments (optional): C:\Veeam_Email\veeam_email.ps1 (this path is unique to where you put your file)

Conditions:
-Start the task only if the computer is on AC power
-Wake the computer to run this task

Settings:
-Allow task to be run on demand
-Stop the task if it runs longer than: 1 hour
-If the running task does not end when requested, force it to stop


Once I set it up with those selections it began to work.
VMCE v9
JaxIsland7575
Veeam Vanguard
 
Posts: 364
Liked: 98 times
Joined: Mon Apr 27, 2015 1:59 pm
Location: NY, USA
Full Name: Ryan Jacksland

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

Veeam Logoby ominfo » Fri May 22, 2015 5:56 pm

OK i will test it right now ! thank you
ominfo
Novice
 
Posts: 7
Liked: never
Joined: Fri May 15, 2015 4:45 pm
Full Name: Olivier Martin

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

Veeam Logoby JaxIsland7575 » Fri May 22, 2015 6:57 pm

One thing to keep in mind is prior to setting up this task, I opened PowerShell as Administrator and ran: Set-ExecutionPolicy unrestricted

After that I setup the job and it worked.
VMCE v9
JaxIsland7575
Veeam Vanguard
 
Posts: 364
Liked: 98 times
Joined: Mon Apr 27, 2015 1:59 pm
Location: NY, USA
Full Name: Ryan Jacksland

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

Veeam Logoby ominfo » Fri May 22, 2015 7:16 pm

Yes thanks for the advice, already done :)
ominfo
Novice
 
Posts: 7
Liked: never
Joined: Fri May 15, 2015 4:45 pm
Full Name: Olivier Martin

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

Veeam Logoby JaxIsland7575 » Fri May 22, 2015 8:06 pm

Were you able to get it running with the new settings?
VMCE v9
JaxIsland7575
Veeam Vanguard
 
Posts: 364
Liked: 98 times
Joined: Mon Apr 27, 2015 1:59 pm
Location: NY, USA
Full Name: Ryan Jacksland

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

Veeam Logoby ominfo » Sat May 23, 2015 12:47 am

Case # 00917535

Work like a charm !! Thanks a lot !
ominfo
Novice
 
Posts: 7
Liked: never
Joined: Fri May 15, 2015 4:45 pm
Full Name: Olivier Martin

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

Veeam Logoby Mike Resseler » Sat May 23, 2015 6:42 pm

Oliver!

Sweet! Thanks for letting us know

Mike
Mike Resseler
Veeam Software
 
Posts: 3494
Liked: 390 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 starcom » Fri Jun 05, 2015 1:37 am

Thanks for the script
if i want to send it via smtp.gmail.com where do i enter the email password?

TIA
starcom
Lurker
 
Posts: 1
Liked: never
Joined: Sun May 31, 2015 4:40 pm
Full Name: Starcom IT

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

Veeam Logoby Mike Resseler » Fri Jun 05, 2015 4:41 am

Starcom,

You can't. Task Scheduler does not support authentication for that job. However, you can use a program (for example SendEmail) and trigger a oneliner as a program with the authentication in

Mike
Mike Resseler
Veeam Software
 
Posts: 3494
Liked: 390 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 Dima P. » Fri Jun 05, 2015 11:43 am

if i want to send it via smtp.gmail.com where do i enter the email password?

I would say you don’t need to authenticate, since the SMTP server is used only to send email - no authentication is required (regularly, it’s just based on the domain name in the email address ). Of course some servers might block the unauthorized access but using the password would not solve it, only connecting from the proper IP address.
Dima P.
Veeam Software
 
Posts: 6739
Liked: 482 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 Allan20 » Mon Aug 24, 2015 7:31 am

Hi

After the endpoint backup has run. The blue window for powershell pops up and then runs the script to send the email.. Is there anyway to make that window hidden?
Allan20
Lurker
 
Posts: 1
Liked: never
Joined: Mon Aug 24, 2015 7:29 am

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

Veeam Logoby SaschaH » Mon Aug 24, 2015 10:37 am 1 person likes this post

Hi Allan,

yes, but you have to use a little "VBScript-Wrapper". I found this a while ago:

Code: Select all
Dim objShell,objFSO,objFile
Set objShell=CreateObject("WScript.Shell")
Set objFSO=CreateObject("Scripting.FileSystemObject")

strPath="<path>\<yourscript>.ps1"

set objFile=objFSO.GetFile(strPath)
strCMD="powershell -nologo -command " & Chr(34) & "&{" &_
objFile.ShortPath & "}" & Chr(34)
objShell.Run strCMD,0


Be sure to edit strPath!

Sascha
SaschaH
Influencer
 
Posts: 12
Liked: 7 times
Joined: Thu Aug 20, 2015 10:23 am
Full Name: Sascha Hoehne

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

Veeam Logoby chris.clark » Wed Aug 26, 2015 11:29 am

Hi
Thanks for script, however when it runs on my machine it bring up an error.

Line 2, Char 1 Error: Invalid Character Code: 800A0408 Source: Microsoft VBScript Compilation error

Sorry, I'm not a VB expert so not sure what to do.

Could you help

Thanks

Chris
chris.clark
Lurker
 
Posts: 1
Liked: never
Joined: Wed Aug 26, 2015 11:21 am
Full Name: Chris Clark

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

Veeam Logoby UniSys » Mon Sep 07, 2015 7:08 am 1 person likes this post

Thanks for the script!

I use VEB to backup several computers so I prefer to have single mail showing the backup status for my all computers. I also use colors in my reports. Let me share my additions:

Code: Select all
###########################################################
# Edit this part:
$youremailserver=    "mail.my.lan"
$sender      =   "backup@my.lan"
$recipient   =   "admin@my.lan"
###########################################################

$Servernames = "srv01","srv02","srv03"
$Body =" <br> "

foreach ($Servername in $Servernames)

{
 
# init variables
$TimeGenerated = ""
$Source = ""
$EntryType = ""
$Message = ""
$InstanceID = ""

$TimeGenerated   =    get-eventlog -LogName "Veeam Endpoint Backup" -computername $Servername -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-List -property TimeGenerated | out-string
$Source      =   get-eventlog -LogName "Veeam Endpoint Backup" -computername $Servername -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-List -property Source | out-string
$EntryType   =   get-eventlog -LogName "Veeam Endpoint Backup" -computername $Servername  -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-List -property EntryType | out-string
$Message   =   get-eventlog -LogName "Veeam Endpoint Backup" -computername $Servername -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-List -property Message | out-string
$InstanceID   =   get-eventlog -LogName "Veeam Endpoint Backup" -computername $Servername -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-List -property InstanceID| out-string


# Add another line to message body according to the result of the backup:

if ($Message.contains("Success")) {
   $Body += "<font style = BACKGROUND-COLOR:green face=Arial color=white>$Message</font> <br>"
   $Body += "<font face=Arial> $TimeGenerated   $InstanceID <br> <br> </font> "
} elseif ($InstanceID.contains("110")) {
   $Body += "<font style = BACKGROUND-COLOR:orange face=Arial color=white>$Message</font> <br>"
   $Body += "<font face=Arial> $TimeGenerated $InstanceID <br> <br> </font> "
}   
   elseif ($InstanceID.contains("")) {
   $Body += "<font style = BACKGROUND-COLOR:red face=Arial color=white> $Servername : No messages logged </font> <br>"
   $Body += "<font face=Arial> $TimeGenerated $InstanceID <br> <br> </font> "
}   
 else {   
   $Body += "<font style = BACKGROUND-COLOR:red face=Arial color=white>$Message</font> <br>"
   $Body += "<font face=Arial> $TimeGenerated $InstanceID <br> <br> </font> "
}
}


Send-MailMessage -To $recipient -Subject "Backup report" -From $sender -Body $Body -BodyAsHtml -SmtpServer $Youremailserver



I am not Powershell scripting expert so my coding style is not perfect. :) But this script works fine for me.

We use VBR free on the same site and I would like to include VMs backup status in my report.
UniSys
Influencer
 
Posts: 24
Liked: 4 times
Joined: Wed Aug 12, 2015 6:34 am
Full Name: Nikolay

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

Veeam Logoby Dima P. » Wed Sep 09, 2015 3:52 pm

Well done Nikolay! Thanks for sharing, may I call it a new edition of color coded email notification scrip for VEB :mrgreen:
Dima P.
Veeam Software
 
Posts: 6739
Liked: 482 times
Joined: Mon Feb 04, 2013 2:07 pm
Location: SPb
Full Name: Dmitry Popov

PreviousNext

Return to Veeam Agent for Windows



Who is online

Users browsing this forum: No registered users and 1 guest