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 GREEN » Sat May 07, 2016 1:35 pm

hi guys
any one give the vdo link. i don't know abt powershell script .
GREEN
Novice
 
Posts: 9
Liked: never
Joined: Mon Apr 11, 2016 2:38 pm
Full Name: northafrica

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

Veeam Logoby Bartk » Sun Jun 26, 2016 3:27 am

I have update the VEB to the latest to test the email notification and this is NOT working with Office 365 smtp relay

There is no option to set it up this way
https://www.veeam.com/kb2109 was useless ......
Back to the powershell script. If anyone has gotten the relay to work with 1.5 update would be great to hear how.

Cheers
Bartk
Novice
 
Posts: 3
Liked: never
Joined: Sun Jun 26, 2016 3:11 am

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

Veeam Logoby Bartk » Mon Jun 27, 2016 11:53 pm

Please disregard the post above
I was impatient and just had to wait so this in fact is working fine...
Bartk
Novice
 
Posts: 3
Liked: never
Joined: Sun Jun 26, 2016 3:11 am

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

Veeam Logoby Dima P. » Tue Jun 28, 2016 12:33 am

Hi Bartk,

Thanks for the heads up! Any tips on office 365 email report configuration or it was just the delivery delay?
Dima P.
Veeam Software
 
Posts: 6497
Liked: 454 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 Bartk » Fri Jul 08, 2016 1:44 am

This was just delivery delay
Bartk
Novice
 
Posts: 3
Liked: never
Joined: Sun Jun 26, 2016 3:11 am

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

Veeam Logoby gveat » Thu Mar 02, 2017 9:02 pm

I would love to output one of these scripts to an HTML file instead of sending it in an email. How would I do so?
gveat
Influencer
 
Posts: 17
Liked: 2 times
Joined: Thu Sep 29, 2016 6:21 pm
Full Name: Greg Veater

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

Veeam Logoby Mike Resseler » Fri Mar 03, 2017 7:27 am

Hi Greg,

Have a look here, this is a good starter on how to create an HTML file through PowerShell. https://technet.microsoft.com/en-us/lib ... 30936.aspx

Based on the already existing scripts, you could then output the data to an HTML file and then use that to store it somewhere (or even send it as an attachment)
Mike Resseler
Veeam Software
 
Posts: 3345
Liked: 380 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 gveat » Fri Mar 03, 2017 2:26 pm

I added the following at the end of the script to output it to a file, in a folder I created each day.

Code: Select all
#output to file
 $date = (get-date)
 $File=("\\server\share\$($date.ToString('MM-dd-yyyy'))\VeeamAgent.html")
if ($InstanceID.contains("190")) {
   $Body | Out-File -FilePath $File
} else {
   write-host "I don't want messages on 10010 and 10050 Restorepoint-creation or -remove Emails, skip those"
}


I use this to create the folder in an addition script, but it could be added to this one to create the folder.
Code: Select all
$Folder = "\\server\share\$((get-date).ToString('MM-dd-yyyy'))"
New-Item -ItemType Directory -path $Folder
gveat
Influencer
 
Posts: 17
Liked: 2 times
Joined: Thu Sep 29, 2016 6:21 pm
Full Name: Greg Veater

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

Veeam Logoby gveat » Fri Mar 03, 2017 2:30 pm

I am having an issue getting the storage numbers to add to the file though. When I run the script I get the following error;
**I am using this with Veeam Agent for Windows. Everything works fine except this one part. You do have to change the source for the event to "Veeam Agent" to get it to work.**


PS C:\Windows\system32> C:\PS\VeeamAgent.ps1
Exception calling "Fill" with "1" argument(s): "Invalid object name 'VeeamBackup.dbo.ReportSessionView'."
At C:\PS\VeeamAgent.ps1:56 char:1
+ $readAdapter.Fill($readSet) |out-null
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SqlException

Script finished with -

InstanceId : 190



- as the last event-ID
gveat
Influencer
 
Posts: 17
Liked: 2 times
Joined: Thu Sep 29, 2016 6:21 pm
Full Name: Greg Veater

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

Veeam Logoby JudgeFudge » Tue Mar 07, 2017 7:50 am

If you are using my script maybe you could do it all in one. I mean, you already have a html body so it is not difficult to use it to export it to a specific folder

I will try to test it and send you the results or the changes i made.
JudgeFudge
Influencer
 
Posts: 15
Liked: 8 times
Joined: Thu Jan 07, 2016 4:54 pm
Location: Germany
Full Name: Chris

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

Veeam Logoby JudgeFudge » Tue Mar 07, 2017 8:33 am

Well this was a quick one.

Just make following changes:

Delete all the E-mail and SMTP Server Information except $hostname.
Adjust the $date = get-date -format F according to your time format -> https://technet.microsoft.com/en-us/library/ee692801.aspx

change the complete send the e-mail section and adjust the $creationdate according to the format you want to name your folder:

Code: Select all
if ($InstanceID.contains("190")) {

$creationdate = get-date -format "M-d-yyyy"
$foldername = $creationdate.ToString()

$path = "C:\path\where\to\create\folder\" // UNC Paths are also possible

New-Item -Path $path -Name "$foldername" -ItemType directory

$file = $path + $foldername

ConvertTo-HTML -body $Body | Out-File "$file\Test.htm"


} 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"


Script creates now a Folder according to the date when the script triggered and writes a html file in it.
Keep in mind that when you already have an existing folder with this date the script returns in error. Give it a try and test it a few days.

If you have any trouble with this write me a message.

Regards
JudgeFudge
Influencer
 
Posts: 15
Liked: 8 times
Joined: Thu Jan 07, 2016 4:54 pm
Location: Germany
Full Name: Chris

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

Veeam Logoby gveat » Tue Mar 07, 2017 4:11 pm

Thank you clearing that up and making it much easier for a single script.
I still receive the error:

Exception calling "Fill" with "1" argument(s): "Invalid object name 'VeeamBackup.dbo.ReportSessionView'."
At C:\PS\VeeamAgent.ps1:56 char:1
+ $readAdapter.Fill($readSet) |out-null
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SqlException
gveat
Influencer
 
Posts: 17
Liked: 2 times
Joined: Thu Sep 29, 2016 6:21 pm
Full Name: Greg Veater

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

Veeam Logoby JudgeFudge » Tue Mar 07, 2017 9:05 pm

I really have no Idea where this error is coming from.
You can try following: Install latest .NET frameworks (4 and higher idk what is the latest version)
Try to run latest version from VEB. Try it with a newer version of powershell maybe.

Do you have any information about the system you are using? Would be helpful to know what version of VEB you are using and what operating system you are running. In my case the script ran successfully on windows 7, 8.1, 10 (inclusive anniversary update) and windows server 2008 R2 and 2012 R2 and latest VEB version. No guarantee for other systems but I think I've already mentioned it. But at least even there shouldn't be any problems.
In addition post or send the full script.
JudgeFudge
Influencer
 
Posts: 15
Liked: 8 times
Joined: Thu Jan 07, 2016 4:54 pm
Location: Germany
Full Name: Chris

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

Veeam Logoby Glaster » Mon Aug 07, 2017 8:08 am

Hello,
Do you already have updated powershell script for new version (Veeam Agent for Windows free)???

Thanks
Glaster
Lurker
 
Posts: 1
Liked: never
Joined: Mon Aug 07, 2017 8:05 am
Full Name: Bohuslav Pindryc

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

Veeam Logoby abelliniSIBA » Tue Aug 08, 2017 2:44 pm

Glaster wrote:Hello,
Do you already have updated powershell script for new version (Veeam Agent for Windows free)???

Thanks


Hello Glaster
here is the newer version.

Code: Select all
# +----------------------------------------------------------------------------+
# |NAME: MailAgentSummary.ps1                                               |
# |AUTHOR: Alessandro                                                          |
# |DATE: 08/08/2017                                                            |
# |VERSION: 1.1                                                                |
# |                                                                            |
# |KEYWORDS:  Veeam, notification, backup, Eventlog, Agent                  |
# |                                                                            |
# |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 08/12/2015 1.0  Endpoint version Notification   
# | Alessandro Bellini 08/08/2017 1.1  Veeam Agent version Notification   
# +----------------------------------------------------------------------------+
#paramter of the script fonction
Param (
   $computers,
   [string]$SmtpServer = "ip_address",
   [string]$From = "sender",
   [string]$To = "destination",
   [switch]$EmailLog,
   [string]$Outpufilehtml
)
#start
Begin
{
   $script:CurrentErrorActionPreference = $ErrorActionPreference
   $script:Output = @()
   $script:ProcessedServers = @()
   $ErrorActionPreference = "SilentlyContinue"
   $script:Subject = @()
   $script:TimeGeneratedJob = @()
   $script:MessageJob = @()
   $script:Status = 1
   $script:ErrorMessage = 0
   $script:WarningMessage = 0
   $script:EnabledMessage = 0
   $script:NbSrvMessage = 0
   # table style for the Email
   $Table = @{ Name = "Server Name"; expression = { $_.servername } }, @{ Name = "Job start"; expression = { $_.TimeGenerated } }, @{ Name = "Job finish"; expression = { $_.TimeGeneratedJob } }, @{ Name = "EntryType"; expression = { $_.EntryType } }, @{ Name = "Source"; expression = { $_.Source } }, @{ Name = "InstanceID"; expression = { $_.InstanceID } }, @{ Name = "Message"; expression = { $_.Message } }
   
   if ($computers)
   {
      if (Test-Path $computers[0]) { $ServerList = Get-Content -Path $computers}
      else { $ServerList = $computers }
   }
   
   ########## START FUNCTION SECTION ###############
   #fonction from website to Set the color line in table
   Function AlternatingRows
   {
      [CmdletBinding()]
      Param (
         [Parameter(Mandatory,
                ValueFromPipeline)]
         [string]$Line
      )
      Begin
      {
         $ClassName = 1
      }
      Process
      {
         If ($Line.Contains("<tr>"))
         {
            If ($ClassName)
            {
               $ClassName = 0
               $ClassColor = "background-color:#3d7e00;"
            }
            Else
            {
               $ClassName = 1
               $ClassColor = "background-color:#afff61;"
            }
            If ($Line.Contains("Warning"))
            {
               $ClassColor = "background-color:#FFD700;"
            }
            If ($Line.Contains("Failed"))
            {
               $ClassColor = "background-color:#fc0200;"
            }
            $Line = $Line.Replace("<tr>", "<tr style=""$ClassColor"">")
         }
         Return $Line
      }
   }
   
   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 -ComputerName $SServer -LogName "Veeam Agent" -InstanceId 190 -newest 1 -entrytype Information, Warning, Error -source "Veeam Agent" | Format-List -property TimeGenerated | out-string).substring(20)
      $MessageJob = (get-eventlog -ComputerName $SServer -LogName "Veeam Agent" -InstanceId 190 -newest 1 -entrytype Information, Warning, Error -source "Veeam Agent" | Format-List -property Message | out-string).substring(14)
#      $TimeGenerated = (get-eventlog -ComputerName $SServer -LogName "Veeam Agent" -InstanceId 150, 110 -newest 1 -entrytype Information, Warning, Error -source "Veeam Agent" | Where { $_.message -match $SServer } | Format-List -property TimeGenerated | out-string).substring(20)
      $Source = (get-eventlog -ComputerName $SServer -LogName "Veeam Agent" -InstanceId 150, 110 -newest 1 -entrytype Information, Warning, Error -source "Veeam Agent" | Where { $_.message -match $SServer } | Format-List -property Source | out-string).substring(13)
      $EntryType = (get-eventlog -ComputerName $SServer -LogName "Veeam Agent" -InstanceId 150, 110 -newest 1 -entrytype Information, Warning, Error -source "Veeam Agent" | Where { $_.message -match $SServer } | Format-List -property EntryType | out-string).substring(16)
      $Message = (get-eventlog -ComputerName $SServer -LogName "Veeam Agent" -InstanceId 150, 110 -newest 1 -entrytype Information, Warning, Error -source "Veeam Agent" | Where { $_.message -match $SServer } | Format-List -property Message | out-string).substring(14)
      $InstanceID = (get-eventlog -ComputerName $SServer -LogName "Veeam Agent" -InstanceId 150, 110 -newest 1 -entrytype Information, Warning, Error -source "Veeam Agent" | 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 TimeGeneratedJob $TimeGeneratedJob -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"))
      {
         $subject1 = "Veeam Endpoint Backup finished with Success."
      }
      else
      {
         if ($MessageJob.contains("no info"))
         {
            $subject1 = "Veeam Endpoint Backup finished with Warning!! Check Body for details."
            $script:WarningMessage += 1
         }
         else
         {
            #$subject1 = "Veeam Endpoint Backup failed!! Check Body for details."
            #$script:ErrorMessage += 1
         }
      }
      
      if ($MessageJob.contains("Failed"))
      {
         $subject1 = "Veeam Endpoint Backup Job failed, Check Body for details."
         $script:ErrorMessage += 1
      }
      elseif ($MessageJob.contains("Warning"))
      {
         $subject1 = "Veeam Endpoint Backup Job finished with Warning Check Body for details."
         $script:WarningMessage += 1
      }
      $subject = "Veeam Endpoint Backup"
                #Export values
      $script:NbSrvMessage +=1
      $script:Output += $Object
      $script:subject = $subject
      $script:TimeGeneratedJob = $TimeGeneratedJob
      $script:MessageJob = $Message
      
   }
}
#process of the script
Process
{
   if ($ServerList)
   {
      foreach ($computer in $ServerList)
      {
         GetEventlog $computer
      }
      #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 ($script:WarningMessage) { $Status = 2 }
   if ($script:ErrorMessage) { $Status = 0 }
      
   if ($Status -eq 1)
      {
         $colorTagTable = "background-color:#3d7e00"
         $messageinfo = "Success"
      }
      elseif ($Status -eq 2)
      {
         $colorTagTable = "background-color:#FFD700"
         $messageinfo = "Warning"
      }
      else
      {
         $colorTagTable = "background-color:#fc0200"
         $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>
       </br> 
   <div><b>Total : $script:NbSrvMessage Servers</div></b> 
            </br>
             <div>Created by $env:username at $date.</div>
         </td>
          <td style="border: none;$colorTagTable;" >
             finished with: <b>$messageinfo</b>
               <div>
               <div>         <b>Errors: $script:ErrorMessage Backup error</b></div>
               <div>         <b>Warning: $script:WarningMessage  Backup warning</b></div>
        </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
      
      #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 ($Outpufilehtml)
      {
         $Body | Out-File $OutpufileHtml
         
      }
      $ErrorActionPreference = $script:CurrentErrorActionPreference
   }


You can schedule this with those parameters:

-file "C:\script\MailAgentSummary.ps1" -computers ".\servers.txt" -OutpufileHtml .\VeeamEndpoints.html -EmailLog

In the same folder you have to create a file server.txt file with clients needed, one for each line.
Verify to use a service account with rights to connect remotly on clients to read the event viewer.

Hope this could help you

Regards

Alessandro
abelliniSIBA
Novice
 
Posts: 9
Liked: 5 times
Joined: Wed Nov 19, 2014 2:01 pm
Full Name: Alessandro Bellini

Previous

Return to Veeam Agent for Windows



Who is online

Users browsing this forum: Bing [Bot], vClintWyckoff and 12 guests