# 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

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

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

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

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: 5942
Liked: 421 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

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

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

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: 2983
Liked: 354 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

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

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

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

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 possibleNew-Item -Path $path -Name "$foldername" -ItemType directory$file =$path + $foldernameConvertTo-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

Thank you clearing that up and making it much easier for a single script.

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

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)

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

Previous