PowerShell script exchange
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

It's not older or something, it's just different - full self-contained VM backup (created by VeeamZIP) has never been designed with disk exclusion feature in my mind. Thanks!
mkaec
Veteran
Posts: 462
Liked: 133 times
Joined: Jul 16, 2015 1:31 pm
Full Name: Marc K
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by mkaec »

It is older as far as being a free option available pre-9.5U4.
emcclure
Influencer
Posts: 22
Liked: never
Joined: Oct 23, 2018 9:02 pm
Contact:

[MERGED] Backup VM's one at a time from a csv list

Post by emcclure »

Hello,

I'm very new to this and think I have it figured out, but I'm still learning PowerShell, so I'm not 100% sure yet. I need to backup VM's from a specific set of folders in a vCenter. I have a script that can run in PowerCLI that will give the info in a csv format which is fine. However I need to back those VM's up but one at a time. I have other scripts that do this, but I've manually entered those in a script as they'll never change. For this particular one though the VM's can change whenever, so I'll have to make this a scheduled task as well to run every so often to make sure the list is current before running the backup. For the backup script I have this:

Code: Select all

Add-PSSnapin veeampssnapin
 $job = "VMware - Interop-VC01"
 $backup = Import-csv c:\BackupScript\VMstoBackup -header Name
 Add-VBRViJobObject -job $job -Entities (Find-VBRViEntity -name $backup.vm)
Which I found here: https://vmcharlie.wordpress.com/2015/06 ... -csv-file/

However I need to back it up one at a time. So I copied this from the other script where it does that:

Code: Select all

Asnp VeeamPSSnapin

    $mbody = @()
    $VMName = ""

    foreach ($VMName in $VMNames)
    {

    $VM = Find-VBRViEntity -Name $VMName
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention

    If ($EnableNotification)
    {
    $TaskSessions = $ZIPSession.GetTaskSessions()
    $FailedSessions = $TaskSessions | where {$_.status -eq "EWarning" -or $_.Status -eq "EFailed"}

    if ($FailedSessions -ne $Null)
    {
    $mbody = $mbody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={$FailedSessions.Title}})
    }

    Else
    {
    $mbody = $mbody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={($TaskSessions | sort creationtime -Descending | select -first 1).Title}})
    }

    }
    }
    If ($EnableNotification)
    {
    $Message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo
    $Message.cc.Add($EmailCC)
    $Message.Subject = $EmailSubject
    $Message.IsBodyHTML = $True
    $message.Body = $mbody | ConvertTo-Html -head $style | Out-String
    $SMTP = New-Object Net.Mail.SmtpClient($SMTPServer)
    $SMTP.Send($Message)
    }
Now normally the $VMNames would be listed at the top and are hardcoded VM's on the other scripts I have that work fine. There's other details in there like for the email and the server I'm backing up to that I decided to leave out for this post. I noticed this line at the top:
Add-VBRViJobObject -job $job -Entities (Find-VBRViEntity -name $backup.vm)

and this down below:

$VM = Find-VBRViEntity -Name $VMName

So would I replace the bottom line with the top line? Since there'd be no $VMNames specified what would I put in for the foreach part? Or is this something I totally have to re-do? Any help is appreciated.

Thanks.
Vitaliy S.
VP, Product Management
Posts: 27055
Liked: 2710 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: Backup VM's one at a time from a csv list

Post by Vitaliy S. »

Hello,

If you need to process VMs one by one, then have you considered limiting the number of tasks on the repository or proxy server? How many virtual disks do your VMs have each? If they have only 1 disk, then just set the concurrent tasks limit to 1 and then start the job with all VMs added to the backup list.

Thank you!
emcclure
Influencer
Posts: 22
Liked: never
Joined: Oct 23, 2018 9:02 pm
Contact:

Re: Backup VM's one at a time from a csv list

Post by emcclure »

Hi Vitaliy,

We don't have a proxy server for this setup. We're using the free version and it's 9.4a if that helps. I'm not sure of the number of disks on these. I was just told that certain machines needed to be backed up and unfortunately that list can change at any time. So the way the script is with the foreach, wouldn't that do the VM's one at a time if it got them from the csv properly? We're trying to automate this with a script so we can have it as a scheduled task to run at certain times. The csv script would probably run every 12 hours to get the latest list of of VM's and then the backup task might run every couple days or so depending on the need.
emcclure
Influencer
Posts: 22
Liked: never
Joined: Oct 23, 2018 9:02 pm
Contact:

Re: Backup VM's one at a time from a csv list

Post by emcclure »

Ok I made a few tweaks, and I have this now:

Code: Select all

$backup = Import-csv c:\BackupScript\VMstoBackup.csv -Header Name -Delimiter ","

foreach ($line in $backup)
    {

    $VM = Find-VBRViEntity -Name $line.Name
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention

    If ($EnableNotification)
    {
    $TaskSessions = $ZIPSession.GetTaskSessions()
    $FailedSessions = $TaskSessions | where {$_.status -eq "EWarning" -or $_.Status -eq "EFailed"}

    if ($FailedSessions -ne $Null)
    {
    $mbody = $mbody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={$FailedSessions.Title}})
    }

    Else
    {
    $mbody = $mbody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={($TaskSessions | sort creationtime -Descending | select -first 1).Title}})
    }

    }
    }
    If ($EnableNotification)
    {
    $Message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo
    $Message.cc.Add($EmailCC)
    $Message.Subject = $EmailSubject
    $Message.IsBodyHTML = $True
    $message.Body = $mbody | ConvertTo-Html -head $style | Out-String
    $SMTP = New-Object Net.Mail.SmtpClient($SMTPServer)
    $SMTP.Send($Message)
    }

However it's failing on line 74 which would be this line: 
$ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention

Tells me this:
Start-VBRZip : Cannot validate argument on parameter 'Entity'. The argument is null. Provide a valid value for the
argument, and then try running the command again.
At C:\BackupScript\BackupVMsInteropVC01.ps1:74 char:40
+     $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compre ...
+                                        ~~~
    + CategoryInfo          : InvalidData: (:) [Start-VBRZip], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.StartVBRZip

And then this for line 78 which is this:
$TaskSessions = $ZIPSession.GetTaskSessions()
You cannot call a method on a null-valued expression.
At C:\BackupScript\BackupVMsInteropVC01.ps1:78 char:5
+     $TaskSessions = $ZIPSession.GetTaskSessions()
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull 
So what am I missing?
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Before we dig deeper into scripting, can you tell me how many VMs are you backing up? I'm wondering because if the number is less than 10, you can use Community Edition and backup jobs instead of scripts. Thanks!
emcclure
Influencer
Posts: 22
Liked: never
Joined: Oct 23, 2018 9:02 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by emcclure »

I wish I had a fixed number, but I'm not sure. Sorry for the late reply, but I suddenly couldn't find this post in my list for some reason. The other day it was 21, today it's 19. Could be 10 tomorrow, could be 30. This team can't give me exacts for whatever reason. I had found a little script that would've imported the csv into a job on the free edition, but that would've been 19 at the moment, and if it's over 10 I'd assume it wouldn't work. My posts seem to keep disappearing, or taking forever to show, so here's what I have at the latest:

Code: Select all

#Import CSV
Add-PSSnapin veeampssnapin
 #$job = "VMware - Interop-VC01"
 $backup = Import-csv c:\BackupScript\VMstoBackup.csv -Header Name -Delimiter ","

....code in between that has the directory, compression level, smtp server, etc

foreach ($vm in $backup)
    {

    $VM = Find-VBRViEntity -Name *
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention

    If ($EnableNotification)
    {
    $TaskSessions = $ZIPSession.GetTaskSessions()
    $FailedSessions = $TaskSessions | where {$_.status -eq "EWarning" -or $_.Status -eq "EFailed"}

    if ($FailedSessions -ne $Null)
    {
    $mbody = $mbody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={$FailedSessions.Title}})
    }

    Else
    {
    $mbody = $mbody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={($TaskSessions | sort creationtime -Descending | select -first 1).Title}})
    }

    }
    }
    If ($EnableNotification)
    {
    $Message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo
    $Message.cc.Add($EmailCC)
    $Message.Subject = $EmailSubject
    $Message.IsBodyHTML = $True
    $message.Body = $mbody | ConvertTo-Html -head $style | Out-String
    $SMTP = New-Object Net.Mail.SmtpClient($SMTPServer)
    $SMTP.Send($Message)
    }

It seems to error out quickly.  I get this error basically:

Start-VBRZip : Cannot validate argument on parameter 'Entity'. The argument is null. Provide a valid value for the
argument, and then try running the command again.
At C:\BackupScript\BackupVMsVC01.ps1:74 char:40
+     $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compre ...
+                                        ~~~
    + CategoryInfo          : InvalidData: (:) [Start-VBRZip], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.StartVBRZip

You cannot call a method on a null-valued expression.
At C:\BackupScript\BackupVMsVC01.ps1:78 char:5
+     $TaskSessions = $ZIPSession.GetTaskSessions()
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
I've tried making changes to this part in regards to the Entities field, but no go. I'm guessing it has something to do with the $VM = Find-VBRViEntity -Name part, but I don't know this well enough. I've tried get-help in PowerShell, but not much luck.
emcclure
Influencer
Posts: 22
Liked: never
Joined: Oct 23, 2018 9:02 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by emcclure »

Soo I made a change and see an improvement.

At the top I just have this now:
$backup = Import-csv -Path "c:\BackupScript\VMstoBackup.csv"

Then all the backup job stuff as stated before.

At the bottom I made this change. I put the $VMs line outside of the foreach loop. Now it gets the list of VM's and starts to back them up. However it seems to be stalled. For about the last 15 minutes it shows Backup job session, the VM to backup and 0 bytes processed. Not sure if I missed something else. Perhaps I need to specify something else telling the Find-VBRViEntity to look at the csv file? Would I need to specify the hosts that the VM's are on in the csv file? Here's a quick snippet of that csv command:

Code for csv

Code: Select all

Get-Datacenter -Name Management | Get-Folder -Name Infrastructure | Get-VM | Select-Object -Property Name | Export-csv VMstoBackup.csv
Rest of backup job code

Code: Select all

$VMs = Find-VBRViEntity -Name * | where {$_.type -eq "VM"}
	
    foreach ($VM in $VMs)
    {
	
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention

    If ($EnableNotification)
    {
    $TaskSessions = $ZIPSession.GetTaskSessions()
    $FailedSessions = $TaskSessions | where {$_.status -eq "EWarning" -or $_.Status -eq "EFailed"}

    if ($FailedSessions -ne $Null)
    {
    $mbody = $mbody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={$FailedSessions.Title}})
    }

    Else
    {
    $mbody = $mbody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={($TaskSessions | sort creationtime -Descending | select -first 1).Title}})
    }

    }
    }
    If ($EnableNotification)
    {
    $Message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo
    $Message.cc.Add($EmailCC)
    $Message.Subject = $EmailSubject
    $Message.IsBodyHTML = $True
    $message.Body = $mbody | ConvertTo-Html -head $style | Out-String
    $SMTP = New-Object Net.Mail.SmtpClient($SMTPServer)
    $SMTP.Send($Message)
    }
I feel like I'm really close here. With this script used in the non-csv way it works quickly. It finds the VM's I hard code in there quickly and starts backing up right away, even with all of the hosts, so this is a concern for me.
emcclure
Influencer
Posts: 22
Liked: never
Joined: Oct 23, 2018 9:02 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by emcclure »

More changes, but no difference. I changed the top to: $VMNames = Import-csv -Path "c:\BackupScript\VMstoBackup.csv"

At the bottom I removed the $VMs = Find-VBRViEntity -Name * | where {$_.type -eq "VM"} and made the following changes for the foreach section:

Code: Select all

foreach ($VMName in $VMNames)
    {
	
	$VM = Find-VBRViEntity -Name $VMName.Name
	
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention
Still the same results though. It acts as if it wants to backup the files, but it's just stuck at 0 bytes. I tried adding a Get-GBRserver and specifying the hosts previously for it to look at those only, but when I tried to pipe that to the Find-VBRViEntity it just started to try and backup every VM on those servers instead of what's on the csv. Really hoping someone can help me here. Feel like I'm so close but so far away at the same time.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

I'd double check:

- whether csv file is structured properly
- whether $VM variable gets assigned properly

Shorten your script and see if everything works as expected:

Code: Select all

$HostName = "Name of vCenter or standalone host VMs to backup reside on"
$Server = Get-VBRServer -name $HostName 
foreach ($VMName in $VMNames)
{
  $VM = Find-VBRViEntity -Name $VMName -Server $Server
  $VM
}
Where $VMNames are taken from .csv file.

Thanks!
emcclure
Influencer
Posts: 22
Liked: never
Joined: Oct 23, 2018 9:02 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by emcclure »

So I found that the other scripts I had that worked just fine before weren't working either. Did a lot of googling, looking at similar issues, trying some different things and nothing working. Wound up rebuilding the backup server with Server 2019. Reinstalled Veeam, reattached network shares, blah blah blah. To make a short story long it appears to be some sort of networking issue, though I'm not 100% sure yet. Even after the rebuild the scripts didn't work right away for whatever reason. I verified all my settings, even rebooted the server and eventually it started working with one of the original scripts. I'm going to let that run over the weekend, then run the next script and finally the one with the csv. It may requires some reboots to work, but I'm hoping somehow I'll figure this out as I want this to be automated. I'd hate to go back to this server all the time to reboot or do whatever is needed to get the backups running properly.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Should the issue appear again, try to split the script into several logical blocks and test them one by one.

This should help to isolate issue to particular part of the script which you can post here later on for further investigation.

Thanks!
emcclure
Influencer
Posts: 22
Liked: never
Joined: Oct 23, 2018 9:02 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by emcclure »

Well it appears that everything is working as far as the scripts go which is great. However I'm noticing now that the backups aren't the correct size. They all appear to be only 2GB each, instead of a lot more as they're supposed to be full backups. This is for any of the scripts that I run and before I had all these issues that wasn't the case. Any idea on why this would suddenly change?
emcclure
Influencer
Posts: 22
Liked: never
Joined: Oct 23, 2018 9:02 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by emcclure »

Ok so if I change the path in the script to backup to the local D drive then the backups become the correct size. However once I change it back to the network drive it puts them back at 2GB. This was not an issue before, so I don't know what would be causing this now. Anybody have any ideas?
emcclure
Influencer
Posts: 22
Liked: never
Joined: Oct 23, 2018 9:02 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by emcclure »

Ok so I even tried this just using the Veeam application. Backed up a machine to the network drive. File shows its a full backup file, but is only 2GB. Backup the same VM to the local drive, shows it's a full backup and is about 16GB. I can't find any difference in the settings for either the network drive or the local drive as far as mapping, so I really don't understand this at all.
emcclure
Influencer
Posts: 22
Liked: never
Joined: Oct 23, 2018 9:02 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by emcclure »

So it gets better. If I do a backup (script/GUI) it shows the file on the NFS as being 2GB when looking thru Windows explorer. When I go into the Veeam Gui and go to Backup Infrastructure -> Backup Repositories it shows a used space on the NFS as 8.4GB. If I then delete that backup and rescan the NFS it shows 0 again, so it's not like there's some sort of hidden files or formatting being used. This is very odd.
emcclure
Influencer
Posts: 22
Liked: never
Joined: Oct 23, 2018 9:02 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by emcclure »

So yesterday I uninstalled Veeam from the server. Went into programdata and deleted everything out of there as well. Installed SSMS and went into SQL and deleted the DB as well. Rebooted. Reinstalled Veeam. Re-added all the hosts and storage. Ran a backup on the NFS share. It worked. Ran another one. It worked again. Currently I'm restoring a VM for another team, but once done I'm going to try my scripts again to make sure there's no new funny business. Hopefully by the end of the week or early next week I'll know this is all working properly. That is of course there's no issues with scheduled tasks. Stay tuned.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

By the way, have you tried to restore 2GB backup? It might be UI or FS glitch that doesn't affect restore activity anyhow.

So, if you it happens again, be sure to verify restore first.

Thanks!
emcclure
Influencer
Posts: 22
Liked: never
Joined: Oct 23, 2018 9:02 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by emcclure »

Yes I did try to restore the 2GB file. It failed miserably.
emcclure
Influencer
Posts: 22
Liked: never
Joined: Oct 23, 2018 9:02 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by emcclure »

So it's working now. After re-reinstalling Veeam all the backups work. Scripts run and backups happen. However it now acts up when it's supposed to do the email portion of the script. I get this stuff:

Code: Select all

New-Object : Exception calling ".ctor" with "2" argument(s): "The parameter 'to' cannot be an empty string.
Parameter name: to"
At D:\BackupScript\BackUpVMs_MYVC01.ps1:108 char:16
+ ...  $Message = New-Object System.Net.Mail.MailMessage $EmailFrom, $Email ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

You cannot call a method on a null-valued expression.
At D:\BackupScript\BackUpVMs_MYVC01.ps1:109 char:5
+     $Message.cc.Add($EmailCC)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

The property 'Subject' cannot be found on this object. Verify that the property exists and can be set.
At D:\BackupScript\BackUpVMs_MYVC01.ps1:110 char:5
+     $Message.Subject = $EmailSubject
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

The property 'IsBodyHTML' cannot be found on this object. Verify that the property exists and can be set.
At D:\BackupScript\BackUpVMs_MYVC01.ps1:111 char:5
+     $Message.IsBodyHTML = $True
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

The property 'Body' cannot be found on this object. Verify that the property exists and can be set.
At D:\BackupScript\BackUpVMs_MYVC01.ps1:112 char:5
+     $message.Body = $mbody | ConvertTo-Html -head $style | Out-String
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

Exception calling "Send" with "1" argument(s): "Value cannot be null.
Parameter name: message"
At D:\BackupScript\BackUpVMs_MYVC01.ps1:114 char:5
+     $SMTP.Send($Message)
+     ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentNullException
Which is driving me nuts. The script I'm even showing here worked originally without any modifications to it other than adding in the VM's at the top of the list. Now it doesn't work. Below is the code that's in all of the scripts for email:

Code: Select all

# Email Settings

    # Enable notification (Optional)
    $EnableNotification = $True

    # Email SMTP server
    $SMTPServer = "redacted"

    # Email FROM
    $EmailFrom = "intopp-vbkup@mydomain.com"

    # Email TO
    #$EmailTo = @('Redacted User <redacted_user@notreal.com>')
    
    # Email CC
    $EmailCC = @('Redacted User 2 <redacted_user2@notreal.com>')
    
    # Email subject
    $EmailSubject = "Veeam Backup Job(s) for $VMNames"
    # Email formatting

    $style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
    $style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
    $style = $style + "TH{border: 1px solid black; background: #54b948; padding: 5px; }"
    $style = $style + "TD{border: 1px solid black; padding: 5px; }"
    $style = $style + "</style>"
So this is just driving me nuts. I'm so close to getting this to fully work, but this happens now. Any ideas on how to fix?
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Give a try a different approach for sending emails via PowerShell; might solve the issue. Thanks!
emcclure
Influencer
Posts: 22
Liked: never
Joined: Oct 23, 2018 9:02 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by emcclure »

I tried that as well. No go. I can telnet to the SMTP server from the host just fine and the script can complete without error, but no email is sent or received. This is really bizarre as it was working before, so I have no idea what could've changed to break it. There's no particular AV software on there that's blocking anything, so I just can't explain this one.
emcclure
Influencer
Posts: 22
Liked: never
Joined: Oct 23, 2018 9:02 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by emcclure »

So I got it to work now with this: Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $EmailSubject -Priority $priority -SmtpServer $smtpServer

However when I enter -Body $mbody -BodyAsHtml or even without the -BodyAsHtml it fails. I have these email settings, with company info removed of course:

Code: Select all

# Email Settings
    #Setup email parameters -------------------------------------------------
    $EmailSubject = "Veeam Backup Job(s) for $VMNames"
    $priority = "Normal"
    $smtpServer = "10.0.0.1"
    $EmailFrom = "backup@notreal.com"
    $EmailTo = "user@notreal.com"
    $port = 25 
        # -----------------------------------------------------------------------
$style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
    $style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
    $style = $style + "TH{border: 1px solid black; background: #54b948; padding: 5px; }"
    $style = $style + "TD{border: 1px solid black; padding: 5px; }"
    $style = $style + "</style>" 

#################### DO NOT MODIFY PAST THIS LINE ################
    Asnp VeeamPSSnapin

    $mbody = @()
    $VMName = ""

   foreach ($VMName in $VMNames)
    {

    $VM = Find-VBRViEntity -Name $VMName
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention

    If ($EnableNotification)
    {
    $TaskSessions = $ZIPSession.GetTaskSessions()
    $FailedSessions = $TaskSessions | where {$_.status -eq "EWarning" -or $_.Status -eq "EFailed"}

    if ($FailedSessions -ne $Null)
    {
    $mbody = $mbody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={$FailedSessions.Title}})
    }

    Else
    {
    $mbody = $mbody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={($TaskSessions | sort creationtime -Descending | select -first 1).Title}})
    }

    }
    }
    If ($EnableNotification)
    {
	Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $EmailSubject -Body $mbody -BodyAsHtml -Priority $priority -SmtpServer $smtpServer
   }

Even using the original code from the script from this site does not work. It used to but I don't know why it fails now. If anybody has any ideas I'd appreciate it as this is the one thing blocking me from getting this finished.
I'm still getting this error:

Code: Select all

Send-MailMessage : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Body'.
Specified method is not supported.
At D:\BackupScript\BackupTest.ps1:93 char:78
+ ... m $EmailFrom -To $EmailTo -Subject $EmailSubject -Body $mbody -BodyAs ...
+                                                                                              ~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Send-MailMessage], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.SendMailMessage
emcclure
Influencer
Posts: 22
Liked: never
Joined: Oct 23, 2018 9:02 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by emcclure »

Seem to have it working now. I basically modified this line:
Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $EmailSubject -Body $mbody -BodyAsHtml -Priority $priority -SmtpServer $smtpServer

to this
Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $EmailSubject -Body ($mbody | Out-String) -Priority $priority -SmtpServer $smtpServer

I found that out here: https://stackoverflow.com/questions/556 ... tem-string

So I get the emails now. They don't have the fancy formatting that the script originally had, but they have the info that we need which is more important than anything else.
simoneg
Novice
Posts: 3
Liked: never
Joined: Jul 10, 2019 2:53 pm
Contact:

[MERGED] Mail report with empty details

Post by simoneg »

HI,
I'm new here.
I installed veeam com. edition Backup&Replication 9.5. in windows server 2012.
I used a famous script in powershell .ps1 for backup my vms (vmware).
The report at the end contains |Name|Start Time|End Time|Result|Details|
But Details are always empty for backup success,warning or failed.
My powershell version is 5.1.

I hope I have written in the right place.
Can you help me?
tnx
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

I'd start with analyzing corresponding variables, whether they contain something or not: $ZIPSession, $Failedsession, $Tasksessions, etc. Thanks!
simoneg
Novice
Posts: 3
Liked: never
Joined: Jul 10, 2019 2:53 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by simoneg »

Code: Select all

Asnp VeeamPSSnapin
$cred = Get-VBRCredentials -Name "DOMAIN\USER"
$Server = Get-VBRServer -name $HostName
$mbody = @()

foreach ($VMName in $VMNames)
{
    $VM = Find-VBRViEntity -Name $VMName -Server $Server
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention -NetworkCredentials $cred


    If ($EnableNotification)
    {
        $TaskSessions = $ZIPSession.GetTaskSessions()
        $FailedSessions = $TaskSessions | where {$_.status -eq “EWarning” -or $_.Status -eq “EFailed”}

        if ($FailedSessions -ne $Null)
        {
            $mbody = $mbody + ($ZIPSession | Select-Object @{n=”Name”;e={($_.name).Substring(0, $_.name.LastIndexOf(“(“))}} ,@{n=”Start Time”;e={$_.CreationTime}},@{n=”End Time”;e={$_.EndTime}},Result,@{n=”Details”;e={$FailedSessions.Title}})
        }
        Else
        {
            $mbody = $mbody + ($ZIPSession | Select-Object @{n=”Name”;e={($_.name).Substring(0, $_.name.LastIndexOf(“(“))}} ,@{n=”Start Time”;e={$_.CreationTime}},@{n=”End Time”;e={$_.EndTime}},Result,@{n=”Details”;e={($TaskSessions | sort creationtime -Descending | select -first 1).Title}})
        }

    }
}
If ($EnableNotification)
{
$Message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo
$Message.Subject = $EmailSubject
$Message.IsBodyHTML = $True
$message.Body = $mbody | ConvertTo-Html -head $style | Out-String
$SMTP = New-Object Net.Mail.SmtpClient($SMTPServer)
$SMTP.Send($Message)
}


$Server = Get-VBRServer -name $HostName2
$mbody = @()

foreach ($VMName in $VMNames2)
{
    $VM = Find-VBRViEntity -Name $VMName -Server $Server
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention -NetworkCredentials $cred


    If ($EnableNotification)
    {
        $TaskSessions = $ZIPSession.GetTaskSessions()
        $FailedSessions = $TaskSessions | where {$_.status -eq “EWarning” -or $_.Status -eq “EFailed”}

        if ($FailedSessions -ne $Null)
        {
            $mbody = $mbody + ($ZIPSession | Select-Object @{n=”Name”;e={($_.name).Substring(0, $_.name.LastIndexOf(“(“))}} ,@{n=”Start Time”;e={$_.CreationTime}},@{n=”End Time”;e={$_.EndTime}},Result,@{n=”Details”;e={$FailedSessions.Title}})
        }
        Else
        {
            $mbody = $mbody + ($ZIPSession | Select-Object @{n=”Name”;e={($_.name).Substring(0, $_.name.LastIndexOf(“(“))}} ,@{n=”Start Time”;e={$_.CreationTime}},@{n=”End Time”;e={$_.EndTime}},Result,@{n=”Details”;e={($TaskSessions | sort creationtime -Descending | select -first 1).Title}})
        }

    }
}
If ($EnableNotification)
{
$Message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo
$Message.Subject = $EmailSubject
$Message.IsBodyHTML = $True
$message.Body = $mbody | ConvertTo-Html -head $style | Out-String
$SMTP = New-Object Net.Mail.SmtpClient($SMTPServer)
$SMTP.Send($Message)
}
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

By analyzing I meant inputting variables into PS console and seeing whether they return something :)

Thanks!
simoneg
Novice
Posts: 3
Liked: never
Joined: Jul 10, 2019 2:53 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by simoneg »

Is your analysis still in progress or can you already give me an opinion?
thanks
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests