PowerShell script exchange
Post Reply
rghabel
Novice
Posts: 3
Liked: never
Joined: May 16, 2019 3:43 pm
Full Name: Robert Ghabel
Contact:

Veeam Backup Script Result in Subject of Email

Post by rghabel »

Hello everyone,

I have been backing up VMs for several years with the script Vladimir wrote back in 2015. It works well and have no problems with the functionality. I am only interested in a simple (hopefully simple) modification.

I have one script that backs up a single VM named "Server" on a VMware 6.7 ESXi host. I have tried modifying this script to put the job result in the email subject line to no avail. Here is what I've tried so far:
If ($EnableNotification)
{
$Message = New-Object System.Net.Mail.MailMessage $EmailFrom, "$EmailTo"
$Message.Subject = "$EmailSubject $VMNames- $_.Status"
$Message.IsBodyHTML = $True
$message.Body = $MesssagyBody | ConvertTo-Html -head $style | Out-String
$SMTP = New-Object Net.Mail.SmtpClient($SMTPServer)
$SMTP.Send($Message)
}

And here is what I receive in the email subject:
Backup Server- .Status

So I can pull the $VMNames to include the name of the VM, but I can't find the right variable to get the job's Result.

Any ideas?
Thanks!
HannesK
Product Manager
Posts: 14837
Liked: 3084 times
Joined: Sep 01, 2014 11:46 am
Full Name: Hannes Kasparick
Location: Austria
Contact:

Re: Veeam Backup Script Result in Subject of Email

Post by HannesK »

Hi,
I'm not a powershell expert, but it would probably help anyone who has more knowledge to have the full script.

I mean, $_. must get data from "somewhere". I'm missing the "somewhere" part.

Best regards,
Hannes
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Veeam Backup Script Result in Subject of Email

Post by veremin »

Hannes is right, you need to put there actual variable, something like:

$ZIPSession.Result or $ZIPSession.Status (don't have a console at hand to confirm the name of actual parameter)

Thanks!
rghabel
Novice
Posts: 3
Liked: never
Joined: May 16, 2019 3:43 pm
Full Name: Robert Ghabel
Contact:

Re: Veeam Backup Script Result in Subject of Email

Post by rghabel »

Well, over the past several months I haven't had the luck that I was hoping for... So far I've tried:

Code: Select all

$ZIPSession.Result = Veeam.Backup.Core.CBackupSession.Result
$ZIPSession.Status = Veeam.Backup.Core.CBackupSession.Status
$ZIPSession.Title   = Veeam.Backup.Core.CBackupSession.Title

I have modified the last section of the script like:
   If ($EnableNotification)
   {
   $Message = New-Object System.Net.Mail.MailMessage $EmailFrom, "$EmailTo4; $EmailTo5"
   $Message.Subject = "$EmailSubject $VMNames- $ZIPSession.Result
   $Message.IsBodyHTML = $True
   $message.Body = $MesssagyBody | ConvertTo-Html -head $style | Out-String
   $SMTP = New-Object Net.Mail.SmtpClient($SMTPServer)
   $SMTP.Send($Message)
   }

Any suggestions?
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Veeam Backup Script Result in Subject of Email

Post by veremin »

You have to take an actual session and assign its properties to $Zipsession variable.

You seem to be using this script, so, I'd recommend checking how the email notification is implemented there.

Thanks!
rghabel
Novice
Posts: 3
Liked: never
Joined: May 16, 2019 3:43 pm
Full Name: Robert Ghabel
Contact:

Re: Veeam Backup Script Result in Subject of Email

Post by rghabel »

Thank you Vladimir. I appreciate your suggestion.
Your right, this is your script. However, I'm not a PS guy. I can script well enough in an old batch file, but those were different times... This has been a pet project for a Church that I volunteer for. All of the rest of our customers have bought and purchased Veeam Enterprise (in paid environments you just don't have this kind of a need).

I've tried looking through the email notification section, but I don't see a variable that is past on to that portion of the script. It looks like the report is past on in it's entirety to the email portion.

I've also looked through Veeam's command line variables and don't see a result variable that could be past on to the email section. So I'm at a loss.
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Veeam Backup Script Result in Subject of Email

Post by veremin » 1 person likes this post

- Running Start-VBRZip returns an object of CBackupSession type (Start-VBRZip <...>)
- You need to assign this object to a variable ($ZIPSession = Start-VBRZip <...>)
- Then, you can query task sessions of this object and check their logs ($TaskSessions = $ZIPSession.GetTaskSessions().logger.getlog().updatedrecords <...>)

Hope it makes sense.

Thanks!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 20 guests