Standalone backup agent for Microsoft Windows servers and workstations (formerly Veeam Endpoint Backup FREE)
GREEN
Novice
Posts: 9
Liked: never
Joined: Apr 11, 2016 2:38 pm
Full Name: northafrica
Contact:

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

Post by GREEN »

hi guys
any one give the vdo link. i don't know abt powershell script .
Bartk
Novice
Posts: 3
Liked: never
Joined: Jun 26, 2016 3:11 am
Contact:

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

Post by Bartk »

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: Jun 26, 2016 3:11 am
Contact:

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

Post by Bartk »

Please disregard the post above
I was impatient and just had to wait so this in fact is working fine...
Dima P.
Product Manager
Posts: 14720
Liked: 1705 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. »

Hi Bartk,

Thanks for the heads up! Any tips on office 365 email report configuration or it was just the delivery delay?
Bartk
Novice
Posts: 3
Liked: never
Joined: Jun 26, 2016 3:11 am
Contact:

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

Post by Bartk »

This was just delivery delay
gveat
Influencer
Posts: 23
Liked: 3 times
Joined: Sep 29, 2016 6:21 pm
Full Name: Greg Veater
Contact:

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

Post by gveat »

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?
Mike Resseler
Product Manager
Posts: 8191
Liked: 1322 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 »

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)
gveat
Influencer
Posts: 23
Liked: 3 times
Joined: Sep 29, 2016 6:21 pm
Full Name: Greg Veater
Contact:

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

Post by gveat » 1 person likes this post

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: 23
Liked: 3 times
Joined: Sep 29, 2016 6:21 pm
Full Name: Greg Veater
Contact:

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

Post by gveat »

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
JudgeFudge
Influencer
Posts: 15
Liked: 8 times
Joined: Jan 07, 2016 4:54 pm
Full Name: Chris
Location: Germany
Contact:

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

Post by JudgeFudge »

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: Jan 07, 2016 4:54 pm
Full Name: Chris
Location: Germany
Contact:

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

Post by JudgeFudge »

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/lib ... 92801.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
gveat
Influencer
Posts: 23
Liked: 3 times
Joined: Sep 29, 2016 6:21 pm
Full Name: Greg Veater
Contact:

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

Post by gveat »

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
JudgeFudge
Influencer
Posts: 15
Liked: 8 times
Joined: Jan 07, 2016 4:54 pm
Full Name: Chris
Location: Germany
Contact:

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

Post by JudgeFudge »

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.
Glaster
Lurker
Posts: 1
Liked: never
Joined: Aug 07, 2017 8:05 am
Full Name: Bohuslav Pindryc
Contact:

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

Post by Glaster »

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

Thanks
abelliniSIBA
Enthusiast
Posts: 32
Liked: 10 times
Joined: Nov 19, 2014 2:01 pm
Full Name: Alessandro Bellini
Location: Italy, Milan
Contact:

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

Post by abelliniSIBA » 1 person likes this post

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
Veolia
andreaf-it
Novice
Posts: 5
Liked: never
Joined: Sep 11, 2018 11:57 am
Full Name: Andrea Fantinel
Contact:

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

Post by andreaf-it »

Hi Alessandro,
I have try to start script but received.
Could you help me?

Code: Select all

Begin : The term 'Begin' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is 
correct and try again.
At C:\Scripts\Test.ps1:42 char:1
+ Begin
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (Begin:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
abelliniSIBA
Enthusiast
Posts: 32
Liked: 10 times
Joined: Nov 19, 2014 2:01 pm
Full Name: Alessandro Bellini
Location: Italy, Milan
Contact:

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

Post by abelliniSIBA »

Hi Andrea,

which version of powershell and OS are you using?
Did you run "c:\> set-executionpolicy unrestricted" before?

Regards
Alessandro
Veolia
andreaf-it
Novice
Posts: 5
Liked: never
Joined: Sep 11, 2018 11:57 am
Full Name: Andrea Fantinel
Contact:

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

Post by andreaf-it »

Hi Alessandro,

Powershell version is 4 0 -1 -1
OS is Windows Server 2012 R2
Yes, i did run "c:\> set-executionpolicy unrestricted" before

thank you for your fast reply
Regards
Andrea
vs-mcooper
Lurker
Posts: 2
Liked: never
Joined: Apr 26, 2023 2:10 pm
Full Name: Michael Cooper
Contact:

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

Post by vs-mcooper »

Hello Everyone,

I am new to the board and I have a question for the author of this script. I apologize if it's already been addressed, however how would I enter my creadentials for a 3rd party email server such as Gmail?

They require a username and password/app password to authenticate.

Thanks for your time,
Michael
Dima P.
Product Manager
Posts: 14720
Liked: 1705 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. » 1 person likes this post

Michael,

These days we have built-in email reporting capabilities in Veeam Agent for Windows, so scripting as in v5 is no longer required for sure. Please take a look: Veeam Agent for Microsoft Windows 6.0 > Enabling Email Notifications.
vs-mcooper
Lurker
Posts: 2
Liked: never
Joined: Apr 26, 2023 2:10 pm
Full Name: Michael Cooper
Contact:

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

Post by vs-mcooper »

Thank you Dima it's very much aprpeciated.
Post Reply

Who is online

Users browsing this forum: No registered users and 38 guests