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 UniSys » Thu Sep 10, 2015 7:34 am 1 person likes this post

Dmitry,

The original idea and original script are not mine, Michael (feelgoodeule) posted it here. I have just shared my additions. So feel free to name it as you wish. :)
UniSys
Influencer
 
Posts: 20
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 feelgoodeule » Thu Sep 10, 2015 8:01 am 1 person likes this post

Hello UniSys,

thank you for leaving the credits to me ;-)

I read your addition to my script. My first thought was, wow, that is smart idea to read the event-log of remote computers from a central one!

But: I trigger my script on the computer which is backed up by VEB, the trigger is an event on that computer (backup started, finished etc).
These triggers don't exist on the central computer which runs your script! How do you trigger the script instead?

I don't understand get this part.

Thanks for sharing, 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 UniSys » Thu Sep 10, 2015 9:38 am

Michael,

To read event log event on remote computer I use 'get-eventlog' command together with '-computername' key. This way you can start your script on one PC and let it connect to event log on another PC.
UniSys
Influencer
 
Posts: 20
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 feelgoodeule » Thu Sep 10, 2015 10:51 am

Hello Unisys

Yes, I know the way you read the event log of the remote computer.
But again: How do you trigger the execution of the script on the central server?

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 UniSys » Thu Sep 10, 2015 11:25 am

Michael,

My backup has to be done before 06:00. I start my script on central server via Task Scheduler at 6:15.

So start of the script is not VEB event-driven. Is it what you mean?

Sorry for many obvious details. I was not sure which part is unclear.
UniSys
Influencer
 
Posts: 20
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. » Fri Sep 11, 2015 4:35 pm

Guys,
Mind me jump in and ask some question regarding your SMTP configurations :wink:

- Do you use in-house smtp or public mail hosting?
- Does it require authentication?
- Do you use the same email for FROM and TO addresses?

Thanks!
Dima P.
Veeam Software
 
Posts: 5847
Liked: 418 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 sibinsam » Fri Sep 11, 2015 4:37 pm

Dima P. wrote:Guys,
Mind me jump in and ask some question regarding your SMTP configurations :wink:

- Do you use in-house smtp or public mail hosting?
- Does it require authentication?
- Do you use the same email for FROM and TO addresses?

Thanks!


I use smtp server with no authentication.
The from and to addresses are different.
sibinsam
Veeam ProPartner
 
Posts: 64
Liked: 6 times
Joined: Mon Nov 03, 2014 5:31 am
Full Name: Sibin Sam

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

Veeam Logoby Dima P. » Fri Sep 11, 2015 4:41 pm

Hey sibinsam,
smtp server with no authentication

And is that a public smtp server or private one?
Dima P.
Veeam Software
 
Posts: 5847
Liked: 418 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 JaxIsland7575 » Fri Sep 11, 2015 4:43 pm

Dima P. wrote:Guys,
Mind me jump in and ask some question regarding your SMTP configurations :wink:

- Do you use in-house smtp or public mail hosting?
- Does it require authentication?
- Do you use the same email for FROM and TO addresses?

Thanks!


- In-house smtp on exchange
- No authentication - private server
- I use different From and To addresses (I created a Veeam AD account that I use for running the services as well as email)

Cheers!
VMCE v9
JaxIsland7575
Veeam Vanguard
 
Posts: 362
Liked: 97 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 sibinsam » Fri Sep 11, 2015 4:49 pm

Dima P. wrote:Hey sibinsam,
smtp server with no authentication

And is that a public smtp server or private one?


Private smtp server
sibinsam
Veeam ProPartner
 
Posts: 64
Liked: 6 times
Joined: Mon Nov 03, 2014 5:31 am
Full Name: Sibin Sam

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

Veeam Logoby Dima P. » Fri Sep 11, 2015 4:51 pm

Got it! Thanks Sam.
Dima P.
Veeam Software
 
Posts: 5847
Liked: 418 times
Joined: Mon Feb 04, 2013 2:07 pm
Location: SPb
Full Name: Dmitry Popov

[MERGED] Veeam Endpoint Mail HTML Notification script

Veeam Logoby abelliniSIBA » Tue Sep 22, 2015 3:25 pm 2 people like this post

Hi guys,

i wrote a small Powershell script (MailEndpoint.ps1) to notify by mail Endpoint backup, adding a grafic table on body results, and write an html file.
just copy and paste this one in an empty *.ps1 file
than 3 suggestions:

1. Open Powershell and run : PS C:\> set-executionpolicy unrestricted;
2. For my Endpoint installations i add this script on Scheduled Tasks and running on a specified EventID "150" or "190";
3. To schedule this script you need to personalize some attribbute (SMTPServer, SMTPsender, SMTPreceiveraddress) and run it with 2 options (as the following example):

PS C:\>.\MailEndpoint.ps1 -SourceServer SERVERNAME -EmailLog (you can create a batch file with these arguments)

where SERVERNAME is the name of your machine. Verify to have the access on your local relay or smtp server
Code: Select all
# +----------------------------------------------------------------------------+
# |NAME: MailEndpoint.ps1                                                            |
# |AUTHOR: Alessandro                                                                 |
# |DATE: 22/09/2015                                                                    |
# |VERSION: 1.0                                                                            |
# |                                                                                               |
# |KEYWORDS:  Veeam, notification, backup, Eventlog, Endpoint    |
# |                                                                                               |
# |COMMENTS: mail the event success\not from windows Event log   |
# |                                                                                               |
# |PARAMETER :                                                                           |
# |    smtpserver use this to change the default smtp server             |
# |    from: you can specify a dif sender email address                   |
# |    to: same like from                                                                |
# | emailLog:If you whan to send the repport by a email; you need |
# |                smtpserver, from and to varibale                               |
# |    outpufile: if you prefere have file for the repport                   |
# |                                                                                               |
# |NEED : none                                                                             |
# +----------------------------------------------------------------------------+
# +----------------------------------------------------------------------------+
# | Maintenance History                                                                |
# | -------------------                                                                      |
# | Name                   Date       Version     Description                    |
# | ---------------------------------------------------------------------------+
# | Alessandro Bellini 22/09/2015 1.0  Endpoint version Notification |
# +----------------------------------------------------------------------------+
 
#paramter of the script fonction
Param(
       $SourceServer,
       [string]$SmtpServer = "SMTPServer",
       [string]$From = "SMTPSender",
       [string]$To = "SMTPreceiveraddress",
       [switch]$EmailLog,
       [string]$Outpufile ="VeamEndpointBackupReport.html"
)
#start
Begin
{
       $script:CurrentErrorActionPreference = $ErrorActionPreference
       $script:Output = @()
       $script:ProcessedServers = @()
       $ErrorActionPreference = "SilentlyContinue"
    $script:Subject = @()
    $script:TimeGeneratedJob = @()
    $script:MessageJob = @()
    $script:Status=1
    # table style for the Email
    $Table = @{Name="Server Name";expression={$_.servername}},@{Name="Time Events (last)";expression={$_.TimeGenerated}},@{Name="EntryType";expression={$_.EntryType}},@{Name="Source";expression={$_.Source}},@{Name="InstanceID";expression={$_.InstanceID}},@{Name="Message";expression={$_.Message}}
   
 
 
       If($EmailLog)
       {     
           
           
           Function SendEmailStatus($From, $To, $Subject, $SmtpServer, $BodyAsHtml, $Body)
           {  $SmtpMessage = New-Object System.Net.Mail.MailMessage $From, $To, $Subject, $Body
                        $SmtpMessage.IsBodyHTML = $BodyAsHtml
                        $SmtpClient = New-Object System.Net.Mail.SmtpClient $SmtpServer
                        $SmtpClient.Send($SmtpMessage)
                       If($? -eq $False){Write-Warning "$($Error[0].Exception.Message) | $($Error[0].Exception.GetBaseException().Message)"}
                        $SmtpMessage.Dispose()
                        rv SmtpClient
                        rv SmtpMessage
           }
    }
 
    Function GetEventlog
    {
    Param( $SServer
                 )
             # Put most info into the body of the email:
        $TimeGeneratedJob=(get-eventlog "Veeam Endpoint Backup" -InstanceId 190 -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-List -property TimeGenerated | out-string).substring(20)
        $MessageJob=(get-eventlog "Veeam Endpoint Backup" -InstanceId 190 -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-List -property Message| out-string).substring(14)
        $TimeGenerated=(get-eventlog "Veeam Endpoint Backup" -InstanceId 150, 110 -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Where {$_.message -match $SServer}| Format-List -property TimeGenerated | out-string).substring(20)
        $Source=(get-eventlog "Veeam Endpoint Backup" -InstanceId 150, 110 -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Where {$_.message -match $SServer} | Format-List -property Source | out-string).substring(13)
        $EntryType=(get-eventlog "Veeam Endpoint Backup" -InstanceId 150, 110 -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Where {$_.message -match $SServer} | Format-List -property EntryType | out-string).substring(16)
        $Message=(get-eventlog "Veeam Endpoint Backup" -InstanceId 150, 110 -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Where {$_.message -match $SServer} | Format-List -property Message| out-string).substring(14)
        $InstanceID=(get-eventlog "Veeam Endpoint Backup" -InstanceId 150, 110 -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Where {$_.message -match $SServer} | Format-List -property InstanceID| out-string).substring(17)
        #check if the value is empty frome the Evente log
        if(!$TimeGenerated)
        {$TimeGenerated ="no info"}
           if(!$Source)
        {$Source ="no info"}
           if(!$EntryType)
        {$EntryType ="no info"}
           if(!$Message)
        {$Message ="no info"}
           if(!$InstanceID)
        {$InstanceID ="no info"}
     
 #Created the PS object for store date in table. and # result screen     
    $Object = New-Object psobject
    $Object | Add-Member NoteProperty Servername $SServer -PassThru |Add-Member NoteProperty TimeGenerated $TimeGenerated -PassThru | Add-Member NoteProperty Source $Source -PassThru |
       Add-Member NoteProperty EntryType $EntryType -PassThru | Add-Member NoteProperty Message $MessageJob -PassThru | Add-Member NoteProperty InstanceID $InstanceID -PassThru
     
# Determine the subject according to the result of the backup:
      if ($MessageJob.contains("Success")) {
           $subject = "Veeam Endpoint Backup finished with Success."
            $script:Status = 1
        } else { 
                    if ($MessageJob.contains("no info")) {
                                        $subject = "Veeam Endpoint Backup finished with Warning!! Check Body for details."
                         $script:Status = 2
                                  }
                           else
                           {
                           $subject = "Veeam Endpoint Backup failed!! Check Body for details."
            $script:Status = 0
                           }
             }     
 
    if ($MessageJob.contains("Failed")) {
$subject = "Veeam Endpoint Backup Job failed, Check Body for details."
$script:Status = 0 }
             elseif ($MessageJob.contains("Warning")) {
             $subject = "Veeam Endpoint Backup Job finished with Warning Check Body for details."
            $script:Status = 2
             }
    #Export values
    $script:Output += $Object
    $script:subject = $subject
    $script:TimeGeneratedJob = $TimeGeneratedJob
    $script:MessageJob = $Message
     
}
}
#process of the script
Process
{
GetEventlog $SourceServer

       #output message resulte
Write-Host "Script finished with : " $script:subject
write-host "Job Message : " $script:MessageJob
write-host "Finished Time Job at : "  $script:TimeGeneratedJob 
}
# the end process task
End
{     
# created the header og the email
 
#definir the color
if($Status -eq 1){
$colorTagTable = "background-color:#7CFC00"
$messageinfo = "Success"
}
elseif ($Status -eq 2) {
$colorTagTable = "background-color:#FFD700"
$messageinfo = "Warning"
}
else{
$colorTagTable = "background-color:#B22222"
$messageinfo = "Error"
}
 
# the header
$htmlbody = ""
$date= Get-Date
$header = @"
 
<table cellspacing="0" cellpadding="0" width="100%" border="0">
 
     <tr>
         <td style="width: 80%;border: none;$colorTagTable;" ><H2>Veeam Endpoint Backup</H2>
       <div>Finished Time Job at $script:TimeGeneratedJob</div></br>     
             <div>Message : $Messagejob</div>
             <div>Created by $env:username at $date.</div>
         </td>
          <td style="border: none;$colorTagTable;" >
             finished with: <b>$messageinfo</b>
        </td>
    </tr>
</table>
"@
#merge body
$htmlbody += $header
#Formating the result in HTML format converting for google mail
$Body = $Output | Select $Table | ConvertTo-HTML -Body $htmlbody
$Body = $Body | AlternatingRows
$Body = $Body -replace '<body>', '<body style = "font-size:12px;font-family:Arial;color:#000000;font-weight:normal">'
$Body = $Body -replace '<table>', '<table style = "border-width:1px;cellpadding=10;border-style:solid;border-collapse:collapse;width:100%">'
$Body = $Body -replace '<th>', '<th style = "font-size:12px;border-width:1px;padding:10px;border-style:solid;background-color:#96C5EC">'
$Body = $Body -replace '<td>', '<td style = "font-size:10px;border-width:1px;padding:10px;border-style:solid">'

Add-Type -AssemblyName System.Web
$Body = [System.Web.HttpUtility]::HtmlDecode($Body) # this line made the link clickable
 
#merge body
$htmlbody +=$header
#fonction to sending the email
If($EmailLog){
SendEmailStatus -From $From -To $To -Subject $script:Subject -SmtpServer $SmtpServer -BodyAsHtml $true -Body $Body
}

#or in a outpute file
if($Outpufile){
$Body | Out-File $OutpufileHtml

}
       $ErrorActionPreference = $script:CurrentErrorActionPreference
}


Hope it could helps you :wink:
Cheers from sunny Italy
Alessandro
abelliniSIBA
Novice
 
Posts: 8
Liked: 5 times
Joined: Wed Nov 19, 2014 2:01 pm
Full Name: Alessandro Bellini

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

Veeam Logoby Dima P. » Tue Sep 22, 2015 3:35 pm 1 person likes this post

Hello Alessandro,
Some folks have already proposed their own scripts, so I merged yours to the existing discussions. Thanks for sharing your approach with the community – it’s highly appreciated!

Cheers from cold and rainy Russia :mrgreen:
Dima P.
Veeam Software
 
Posts: 5847
Liked: 418 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 abelliniSIBA » Tue Sep 22, 2015 3:55 pm

Thanks Dima!
That's why i like that interesting community!
abelliniSIBA
Novice
 
Posts: 8
Liked: 5 times
Joined: Wed Nov 19, 2014 2:01 pm
Full Name: Alessandro Bellini

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

Veeam Logoby vpjax » Fri Oct 23, 2015 2:31 pm

I have expanded on your powershell script to actually grab data from the Veeam DB itself. It is nice to know a little more than the backup completed.

Also note you can use an application such as DeltaCopy to sync these backups to another server or in the cloud. You can hang this script off the event log in task scheduler and then start the rsync sync at the end of this script based on failed or success.


The 2 important added pieces of code are here:

It goes in and queries Veeam's Local DB. It grabs the correct username and password from the Registry and Querys the Report View.

Code: Select all
 
$key = "hklm:\SOFTWARE\Veeam\Veeam Endpoint Backup"
    $TableDetail = Invoke-Sqlcmd -Username (Get-ItemProperty -Path $key -Name SqlLogin).SqlLogin -Password (Get-ItemProperty -Path $key -Name SqlPassword).SqlPassword -ServerInstance (Get-ItemProperty -Path $key -Name SqlInstancePipeName).SqlInstancePipeName -Query "SELECT Top 10 [job_name] as [Job Name],[creation_time] as [Started],[end_time] as [Ended],[is_full] as [Full Backup],[total_size] / 1073741824 as [Total Size GB], [total_used_size] / 1073741824 as [Total Used Size GB], [processed_used_size] / 1073741824 as [Total Processed Used GB],[stored_size] / 1048576 as [Total Stored Size MB],[progress] as [Progress],[is_retry] as [Retry?],[avg_speed] / 1048576 as [Speed MB/min]  FROM [VeeamBackup].[dbo].[ReportSessionView] ORDER BY [creation_time] DESC" |  Select-Object -Property * -ExcludeProperty ItemArray, Table, HasErrors, RowState, RowError  | ConvertTo-HTML


Full Scripts with other additions and changes below:

Code: Select all
# +----------------------------------------------------------------------------+
# |NAME: MailEndpoint.ps1                                                      |
# |AUTHOR: Alessandro                                                          |
# |DATE: 22/09/2015                                                            |
# |VERSION: 1.1                                                                |
# |                                                                            |
# |KEYWORDS:  Veeam, notification, backup, Eventlog, Endpoint              |
# |                                                                            |
# |COMMENTS: mail the event success\not from windows Event log             |
# |                                                                            |
# |PARAMETER :                                                                 |
# |    smtpserver use this to change the default smtp server                   |
# |    from: you can specify a dif sender email address                        |
# |    to: same like from                                                      |
# |    emailLog:If you whan to send the repport by a email; you need           |
# |                smtpserver, from and to varibale                            |
# |    outpufile: if you prefere have file for the repport                     |
# |    SourceClient: Shows in email report                                     |
# +----------------------------------------------------------------------------+
# +----------------------------------------------------------------------------+
# | Maintenance History                                                        |
# | -------------------                                                        |
# | Name                   Date       Version     Description                  |
# | ---------------------------------------------------------------------------+
# | Alessandro Bellini 22/09/2015 1.0  Endpoint version Notification           |
# | Joshua Lee         23/10/2015 1.1  Added Direct DB QUERY for Backup Stats  |
# |                     Added Option SourceClient which adds   |
# |               client name to emailed report. Also    |
# |               changed email subject and added Server |
# |               Name.                   |
# +----------------------------------------------------------------------------+


 
#paramter of the script fonction
Param(
       $SourceServer,
       [string]$SmtpServer = "SMTPServer",
       [string]$From = "SMTPSender",
       [string]$To = "SMTPreceiveraddress",
       [switch]$EmailLog,
       $SourceClient,
       [string]$Outpufile ="VeamEndpointBackupReport.html"
)
#start
Begin
{
       $script:CurrentErrorActionPreference = $ErrorActionPreference
       $script:Output = @()
       $script:ProcessedServers = @()
       $ErrorActionPreference = "SilentlyContinue"
    $script:Subject = @()
    $script:TimeGeneratedJob = @()
    $script:MessageJob = @()
    $script:Status=1
    # table style for the Email
    $Table = @{Name="Server Name";expression={$_.servername}},@{Name="Time Events (last)";expression={$_.TimeGenerated}},@{Name="EntryType";expression={$_.EntryType}},@{Name="Source";expression={$_.Source}},@{Name="InstanceID";expression={$_.InstanceID}},@{Name="Message";expression={$_.Message}}
   
    $key = "hklm:\SOFTWARE\Veeam\Veeam Endpoint Backup"
    $TableDetail = Invoke-Sqlcmd -Username (Get-ItemProperty -Path $key -Name SqlLogin).SqlLogin -Password (Get-ItemProperty -Path $key -Name SqlPassword).SqlPassword -ServerInstance (Get-ItemProperty -Path $key -Name SqlInstancePipeName).SqlInstancePipeName -Query "SELECT Top 10 [job_name] as [Job Name],[creation_time] as [Started],[end_time] as [Ended],[is_full] as [Full Backup],[total_size] / 1073741824 as [Total Size GB], [total_used_size] / 1073741824 as [Total Used Size GB], [processed_used_size] / 1073741824 as [Total Processed Used GB],[stored_size] / 1048576 as [Total Stored Size MB],[progress] as [Progress],[is_retry] as [Retry?],[avg_speed] / 1048576 as [Speed MB/min]  FROM [VeeamBackup].[dbo].[ReportSessionView] ORDER BY [creation_time] DESC" |  Select-Object -Property * -ExcludeProperty ItemArray, Table, HasErrors, RowState, RowError  | ConvertTo-HTML

     If($EmailLog)
       {     
           
           
           Function SendEmailStatus($From, $To, $Subject, $SmtpServer, $BodyAsHtml, $Body)
           {  $SmtpMessage = New-Object System.Net.Mail.MailMessage $From, $To, $Subject, $Body
                        $SmtpMessage.IsBodyHTML = $BodyAsHtml
                        $SmtpClient = New-Object System.Net.Mail.SmtpClient $SmtpServer
                        $SmtpClient.Send($SmtpMessage)
                       If($? -eq $False){Write-Warning "$($Error[0].Exception.Message) | $($Error[0].Exception.GetBaseException().Message)"}
                        $SmtpMessage.Dispose()
                        rv SmtpClient
                        rv SmtpMessage
           }
    }
 
    Function GetEventlog
    {
    Param( $SServer
                 )
             # Put most info into the body of the email:
        $TimeGeneratedJob=(get-eventlog "Veeam Endpoint Backup" -InstanceId 190 -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-List -property TimeGenerated | out-string).substring(20)
        $MessageJob=(get-eventlog "Veeam Endpoint Backup" -InstanceId 190 -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-List -property Message| out-string).substring(14)
        $TimeGenerated=(get-eventlog "Veeam Endpoint Backup" -InstanceId 150, 110 -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Where {$_.message -match $SServer}| Format-List -property TimeGenerated | out-string).substring(20)
        $Source=(get-eventlog "Veeam Endpoint Backup" -InstanceId 150, 110 -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Where {$_.message -match $SServer} | Format-List -property Source | out-string).substring(13)
        $EntryType=(get-eventlog "Veeam Endpoint Backup" -InstanceId 150, 110 -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Where {$_.message -match $SServer} | Format-List -property EntryType | out-string).substring(16)
        $Message=(get-eventlog "Veeam Endpoint Backup" -InstanceId 150, 110 -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Where {$_.message -match $SServer} | Format-List -property Message| out-string).substring(14)
        $InstanceID=(get-eventlog "Veeam Endpoint Backup" -InstanceId 150, 110 -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Where {$_.message -match $SServer} | Format-List -property InstanceID| out-string).substring(17)
        #check if the value is empty frome the Evente log
        if(!$TimeGenerated)
        {$TimeGenerated ="no info"}
           if(!$Source)
        {$Source ="no info"}
           if(!$EntryType)
        {$EntryType ="no info"}
           if(!$Message)
        {$Message ="no info"}
           if(!$InstanceID)
        {$InstanceID ="no info"}
     
 #Created the PS object for store date in table. and # result screen     
    $Object = New-Object psobject
    $Object | Add-Member NoteProperty Servername $SServer -PassThru |Add-Member NoteProperty TimeGenerated $TimeGenerated -PassThru | Add-Member NoteProperty Source $Source -PassThru |
       Add-Member NoteProperty EntryType $EntryType -PassThru | Add-Member NoteProperty Message $MessageJob -PassThru | Add-Member NoteProperty InstanceID $InstanceID -PassThru
     
# Determine the subject according to the result of the backup:
      if ($MessageJob.contains("Success")) {
           $subject = "Veeam Endpoint Backup finished with Success on " + $SServer
            $script:Status = 1
        } else { 
                    if ($MessageJob.contains("no info")) {
                                        $subject = "Veeam Endpoint Backup finished with Warning on " + $SServer + " Check Body for details."
                         $script:Status = 2
                                  }
                           else
                           {
                           $subject = "Veeam Endpoint Backup failed on " + $SServer + "!! Check Body for details."
            $script:Status = 0
                           }
             }     
 
    if ($MessageJob.contains("Failed")) {
$subject = "Veeam Endpoint Backup Job failed on " + $SServer + ", Check Body for details."
$script:Status = 0 }
             elseif ($MessageJob.contains("Warning")) {
             $subject = "Veeam Endpoint Backup Job finished with Warning on " + $SServer + " Check Body for details."
            $script:Status = 2
             }
    #Export values
    $script:Output += $Object
    $script:subject = $subject
    $script:TimeGeneratedJob = $TimeGeneratedJob
    $script:MessageJob = $Message
     
}
}
#process of the script
Process
{
GetEventlog $SourceServer

       #output message resulte
Write-Host "Script finished with : " $script:subject
write-host "Job Message : " $script:MessageJob
write-host "Finished Time Job at : "  $script:TimeGeneratedJob 
}
# the end process task
End
{     
# created the header og the email
 
#definir the color
if($Status -eq 1){
$colorTagTable = "background-color:#7CFC00"
$messageinfo = "Success"
}
elseif ($Status -eq 2) {
$colorTagTable = "background-color:#FFD700"
$messageinfo = "Warning"
}
else{
$colorTagTable = "background-color:#B22222"
$messageinfo = "Error"
}
 
# the header
$htmlbody = ""
$date= Get-Date
$header = @"
 
<table cellspacing="0" cellpadding="0" width="100%" border="0">
 
     <tr>
         <td style="width: 80%;border: none;$colorTagTable;padding:10px;" ><H2>Veeam Endpoint Backup - $SourceClient</H2>
       <div><b>Job Finished at:</b> $script:TimeGeneratedJob</div></br>     
             <div><b>Message:</b> $Messagejob</div>
             <div><b>Client Site:</b> $SourceClient
        <b>Emailed at:</b> $date. <BR />
        <b>Note: </b> ! Check SYNC LOG ! Additional email to Follow.</div>
         </td>
          <td style="border: none;$colorTagTable;padding:10px;" >
             Finished with: <b>$messageinfo</b>
        </td>
    </tr>
</table>
"@

#merge body
$htmlbody += $header
#Formating the result in HTML format converting for mail
$Body = $Output | Select $Table | ConvertTo-HTML -Body $htmlbody
$Body = $Body | AlternatingRows
$Body = $Body -replace '<body>', '<body style = "font-size:12px;font-family:Arial;color:#000000;font-weight:normal">'
$Body = $Body -replace '<table>', '<table style = "border-width:1px;cellpadding=10;border-style:solid;border-collapse:collapse;width:100%">'
$Body = $Body -replace '<th>', '<th style = "font-size:12px;border-width:1px;padding:10px;border-style:solid;background-color:#96C5EC">'
$Body = $Body -replace '<td>', '<td style = "font-size:10px;border-width:1px;padding:10px;border-style:solid">'



#Formating the result in HTML format converting for mail
$Body2 = $TableDetail
$Body2 = $Body2 | AlternatingRows
$Body2 = $Body2 -replace '<body>', '<body style = "font-size:12px;font-family:Arial;color:#000000;font-weight:normal">'
$Body2 = $Body2 -replace '<table>', '<table style = "border-width:1px;cellpadding=10;border-style:solid;border-collapse:collapse;width:100%">'
$Body2 = $Body2 -replace '<th>', '<th style = "font-size:12px;border-width:1px;padding:10px;border-style:solid;background-color:#96C5EC">'
$Body2 = $Body2 -replace '<td>', '<td style = "font-size:10px;border-width:1px;padding:10px;border-style:solid">'

$Body += "<div style=''><BR /> <b>Backup Details:</b><BR></div>" + $Body2

Add-Type -AssemblyName System.Web
$Body += "<div style='font-size:10px;'>Managed by: Venture Pointe, Inc.</div>"


$Body = [System.Web.HttpUtility]::HtmlDecode($Body) # this line made the link clickable
 
#merge body
$htmlbody +=$header

#function to sending the email
If($EmailLog){
SendEmailStatus -From $From -To $To -Subject $script:Subject -SmtpServer $SmtpServer -BodyAsHtml $true -Body $Body
}

#or in a outpute file
if($Outpufile){
$Body | Out-File $OutpufileHtml

}
       $ErrorActionPreference = $script:CurrentErrorActionPreference
}
vpjax
Lurker
 
Posts: 1
Liked: never
Joined: Fri Oct 23, 2015 2:12 pm
Full Name: Josh Lee

PreviousNext

Return to Veeam Agent for Windows



Who is online

Users browsing this forum: Gnaah, ssimakov and 11 guests