Vladimir EreminThis is a guest post by Vladimir Eremin, a product manager at Veeam. Vladimir is very active on the Veeam Forums, Twitter and in Spiceworks. One of Vladimir’s skills is PowerShell and he walks through this process here in this guest blog post. If you have any question on the PowerShell parts mentioned in this post, use the Veeam Forums to discuss. You an also download the sample script here for VMware and the sample script here for Hyper-V and discuss this topic in the Veeam Forums.

Our Veeam Backup Free Edition has been the most popular free Veeam tool, mostly thanks to its VeeamZIP functionality: ability to perform interactive full backups of unlimited amount of VMs. However, VeeamZIP has always had one small yet irritating limitation – the inability to schedule performing regular backups. Indeed, due to the fact that VeeamZIP can only be triggered interactively, there is simply no means in UI to schedule it like regular backup jobs. If you have been down this path, you will be happy to know that as of Update 2, this is no longer the case! In areas like the Veeam forums, our engagement on Twitter and other areas; we have recognized the concern and decided to address it by making Start-VBRZip PowerShell cmdlet available in Free Edition.

4-April 2016 Note: Update your PowerShell to version 3.0 at least prior to using this script, as we’ve discovered number of odd issues while working with PowerShell 2.0.

How it works

As noted earlier, the main functionality Veeam Backup Free Edition is ability to perform VeeamZIP backups of your VMs (and, of course, to recover VMs, guest files and application items from those backups). VeeamZIP always produces a full backup file (.vbk) that acts as an independent restore point. Free Edition allows you to store the backup file on a backup repository, on a local folder or on a network share.

When you perform backup with VeeamZIP, you can start the backup process for selected VM immediately. This type of backup requires minimal settings, and as such is extremely easy to trigger manually.

image

With Update 2, you can now write a simple PowerShell script (here for VMware and here for Hyper-V) that starts VeeamZIP activity for a selected VM, and sets whatever schedule you want for it via Windows Scheduler. We have even created the following example script for you that will not only trigger VeeamZIP backups of the required VMs, but will also email you a nicely formatted report with backup results!

Script parameters

The script is able to perform ad-hoc backup of selected VMs residing on both standalone host or cluster, or vCenter server. Before executing script, you need to provide three mandatory parameters: names of VMs to backup, host those VMs are located at, and directory where backup files should be stored. Note, this script was updated on 5/18 due to feedback.

 

##################################################################

#                   User Defined Variables

##################################################################

 

# Names of VMs to backup separated by comma (Mandatory). For instance, $VMNames = “VM1”,”VM2”

$VMNames = ""

 

# Name of vCenter or standalone host VMs to backup reside on (Mandatory)

$HostName = ""

 

# Directory that VM backups should go to (Mandatory; for instance, C:\Backup)

$Directory = ""

Optionally, you can change compression level and desired retention, disable VMware quiescence, enable encryption or even notification settings:

# Desired compression level (Optional; Possible values: 0 - None, 4 - Dedupe-friendly, 5 - Optimal, 6 - High, 9 - Extreme)

$CompressionLevel = "5"

# Quiesce VM when taking snapshot (Optional; VMware Tools or Hyper-V Integration Components are required for this in the guest OS; Possible values: $True/$False)

$EnableQuiescence = $True

# Protect resulting backup with encryption key (Optional; $True/$False)

$EnableEncryption = $False

# Encryption Key (Optional; path to a secure string)

$EncryptionKey = ""

# Retention settings (Optional; by default, VeeamZIP files are not removed and kept in the specified location for an indefinite period of time.

# Possible values: Never, Tonight, TomorrowNight, In3days, In1Week, In2Weeks, In1Month)

$Retention = "Never"

If you like to get an email report once the backup is completed, you should additionally fill out the following notification settings.

##################################################################

# Notification Settings

##################################################################

# Enable notification (Optional)

$EnableNotification = $True

# Email SMTP server

$SMTPServer = ""

# Email FROM

$EmailFrom = ""

# Email TO

$EmailTo = ""

# Email subject

$EmailSubject = ""

The resulting email report will look like this:

 

Name Start Time End Time Result Details
CentOS-tiny_2015-03-26T180459 3/26/2015 6:04:59 PM 3/26/2015 6:07:17 PM Warning Processing finished with warnings at 3/26/2015 6:07:13 PM Cannot use VMware Tools quiescence because VMware Tools are not found.
CentOS-tiny_replica_2015-03-26T180720 3/26/2015 6:07:20 PM 3/26/2015 6:11:20 PM Success Processing finished at 3/26/2015 6:11:18 PM

All of the abovementioned settings can be configured by setting certain variables to the corresponding values. For instance, to enable encryption, you should set $True (Boolean) value to $EnableEncryption variable, and provide the encryption key (see the next chapter). Additionally, if you want the backup files to be deleted after two weeks, you should set “In2Weeks” (string) value to $Retention variable, etc. There is no need to remember what each and every variable does and what values are acceptable – for your convenience, the example script include a short description for each variable.

Encryption

Getting back to encryption, data security is a critical part of the backup strategy. Backup data must be protected from unauthorized access, especially when a sensitive VM data is backed up to an offsite location or archived to tapes. To keep your data safe, you can encrypt your VeeamZIP backups. As noted above, this requires choosing a file containing the encryption password.

Of course, you could provide the password to a script as a plain text string. However, regular strings are insecure (to the say the least), since they are stored in memory as plain text. As a result, most PowerShell cmdlets will simply not accept passwords in this form.

A secure string is a better option. This type is like the usual string, but its content is encrypted in memory. It uses reversible encryption so the password can be decrypted when needed, but only by the principal that encrypted it. To create a secure string you need to open the PS console, and type the following two lines. When executed, the code will ask you to prompt a password and, then, save it as a secure string into a file:

$SecurePassword = Read-Host -Prompt "Enter password" -AsSecureString

$SecurePassword | ConvertFrom-SecureString > “Directory where secure string should be stored; C:\SecureString.txt, for instance”

After that, specify the path to the newly-created file in the main script:

# Protect resulting backup with encryption key (Optional; $True/$False)

$EnableEncryption = $True

# Encryption Key (Optional; path to a secure string)

$EncryptionKey = "C:\SecureString.txt"

 

Scheduling the script

Before you schedule the script, be sure to try starting it manually to ensure that it performs as expected.

The easiest way to schedule the script to perform periodic backup automatically is to use Windows Task Scheduler. Simply go to the Task Scheduler tool, and create a new basic task:

image

Assign a name and a description for it, so that you can easily remember what this task does.

The next page is the Task Trigger. It is pretty basic, and self-explanatory. The available options are quite flexible (everything from running backups several times a day or once a month is possible), so set there whatever values that address your RPO requirements. Most people use daily backups:

image

Set the start time for the task for the off hours. In this example, the task runs every evening at 22:00 PM beginning on April 22, 2015.

image

On the subsequent Action page, specify that you want the scheduled task to Start a program, and then click Next.

clip_image002

On the Start a Program pane, you place the following command into Program/script:

Powershell –file “Path to Veeamzip.ps1 file”

clip_image004

That’s it! But we may want to open the task once it is created to make a couple of additional changes. To do so, select the Open the Properties dialog for this task when I click Finish:

clip_image006

Since the task is to be run on a server, where a user might not be logged when the task takes place, it is worth to enable the task to run regardless of whether or not the user is logged on by associating the user’s credentials with the task.

clip_image008

Once you’re done, right-click the job and select Run to ensure that the task completes properly:

clip_image009

PowerShell gives the users what they have always wanted from Veeam Backup Free Edition!

Now that you are armed with this new awesome capability, you now should be able to achieve the long-awaited goal – do scheduled backups with the use of Veeam Backup Free Edition, which provides far more backup and recovery features than script-based free backup solution alternatives.

Check out these other cool resources:

GD Star Rating
loading...
Veeam Backup Free Edition: Now with PowerShell!, 4.7 out of 5 based on 21 ratings

View posts related to category:

All Veeam Products Top List
Technology Bloggers on Air
  • Greg Zartman

    There is an error in this script for defining multiple VMs to backup. Here is the line:

    # Names of VMs to backup separated by semicolon (Mandatory)
    $VMNames = “”

    This should instead read:

    # Names of VMs to backup. Define each VM with quotes and separate each quoted VM name with a comma.(Mandatory)
    $VMNames = “”

    Example: $VMNames = “VM1”, “VM2”, “VM3”

  • Rick Vanover

    Hey Greg – thanks for that, Vladimir just sent me a new script – I’m uploading it now.

  • Manuel

    Hi to everybody!

    I’m trying to execute the script on Windows 7 x64 “server” with Veeam Backup & Replication Update 2 installed.

    I receive this error:

    Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 2.
    At C:VeeamZIPVeeamZIP.ps1:69 char:5
    + Asnp <<<< VeeamPSSnapin
    + CategoryInfo : InvalidArgument: (VeeamPSSnapin:String) [Add-PSSnapin], PSArgumentException
    + FullyQualifiedErrorId :

    AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
    The term 'Get-VBRServer' 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:VeeamZIPVeeamZIP.ps1:71 char:24
    + $Server = Get-VBRServer <<<< -name $HostName
    + CategoryInfo : ObjectNotFound: (Get-VBRServer:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    The term 'Find-VBRViEntity' 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:VeeamZIPVeeamZIP.ps1:76 char:25
    + $VM = Find-VBRViEntity <<<< -Name $VMName -Server $Server
    + CategoryInfo : ObjectNotFound: (Find-VBRViEntity:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    The term 'Add-VBREncryptionKey' 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:VeeamZIPVeeamZIP.ps1:80 char:42
    + $EncryptionKey = Add-VBREncryptionKey <<<< -Password (cat $EncryptionKey | ConvertTo-SecureString)
    + CategoryInfo : ObjectNotFound: (Add-VBREncryptionKey:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    The term 'Start-VBRZip' 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:VeeamZIPVeeamZIP.ps1:81 char:31
    + $ZIPSession = Start-VBRZip <<<< -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!
    $EnableQuiescence) -AutoDelete $Retention -EncryptionKey $EncryptionKey
    + CategoryInfo : ObjectNotFound: (Start-VBRZip:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    Any idea of the reason why?
    Thanks a lot.

    • Vladimir Eremin

      Are you positive VB&R snap-in has been installed and registered on the given machine? You can double check it via Get-PSSnapin commandlet.

      • Aleks

        Hi,
        how i can install this snap-in?

        • Vladimir Eremin

          VB&R wizard lists components it’s going to install. Among those there will be a corresponding PS snap-in that you need to select. Thanks.

  • Manuel

    Update.
    I made some fixes and adjustment to Powershell Addins, regedit and some others things.
    Now, I’m stop here:

    Start-VBRZip : License is not installed.
    At C:VeeamZIPStartZip.ps1:24 char:5
    + Start-VBRZip -Entity $vmentity -Folder $destination -Compression $Compressio …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Start-VBRZip], CLicenseNotInstalledException
    + FullyQualifiedErrorId: Veeam.Backup.LicenseLib.CLicenseNotInstalledException,Veeam.Backup.PowerShell.Commands.Backup.StartVBRZip

  • http://blackenedistheend.over-blog.com/ Aurélien

    Hello, thanks for this script.
    It’s working well with a local folder but when I try to backup a VM on a share ($Directory = “\server.domshare$”) I have the following error :
    Error: Accès refusé. Error code: 5
    Cannot create folder. Folder path: [\server.domshare$].
    –tr:FC: Failed to create directory. Directory path: [\server.domshare$].
    –tr:Failed to call DoRpc. CmdName: [FcCreateDir].
    Accès refusé. Error code: 5
    Cannot create folder. Folder path: [\server.domshare$].
    ———————
    I launch Veeam B&R (so the Powershell console) with an domain admin account and in the Powershell console I can access to the share with “cd” command. Veeam B&R is installed on my french Windows 8.1 computer.

  • Manuel

    Salut Aurélien,

    have you tried to set a network unit instead to use the entire network path?
    I mean, on the Veeam server you can create, for example, a V: (or another letter) connected to \server.domshare$, and using this V: on the script.
    This work for me, but I receive another error (Start-VBRZip : License is not installed.).

    • Ryan Lee

      Hi Manuel – I am having the same issue. Please see the post above yours. Thanks.

      • Vladimir Eremin

        Most likely, you haven’t installed Update 2 that makes the said commandlets available in free version.

        • Ryan Lee

          Hi Vladimir, thanks for the reply. I was on Update 2 (8.0.0.2021) when I had the issue. I updated to Update 2a (8.0.0.2029) and can now back up. Thanks again for the script!

  • Manuel

    Aurélien, now I’ve same your issue, so the solution I proposed to you, doesn’t works.

  • Ryan Lee

    Manuel, what did you do to solve your license issue? I am getting the same (Start-VBRZip : License is not installed.) error. I completely reinstalled using a new database and still get this message. Thanks.

  • Martin

    Hi, script is working fine for me, but I get the “Start-VBRZip : License is not installed”
    Any solution? Im using version 8.0.0.817

    • Martin

      Okay, I thought I had the latest update.

      To solve it, go to Veeam official website at: http://www.veeam.com/kb2024
      and download the update.

      Release note: PowerShell Support in Free Edition. Start-VBRZip cmdlet is now enabled in Veeam Backup™ Free Edition, allowing users to schedule periodic VeeamZIP™ backups using external task schedulers, such as Windows Task Scheduler. This should make Veeam Backup Free Edition a viable alternative to ghettoVCB and other similar script-based free backup solutions.

  • Pete

    Hi, Is there anyway the notification can be dumped into a log file instead?

  • Max

    I’m running Veeam FREE Edition with Update 2b on Windows 2012R2 and I getting the following error when trying to run the script. Any ideas?

    Find-VBRViEntity : Cannot validate argument on parameter ‘Server’. The argument is null. Provide a valid value for the
    argument, and then try running the command again.
    At C:VeeamZIP.ps1:76 char:48
    + $VM = Find-VBRViEntity -Name $VMName -Server $Server
    + ~~~~~~~
    + CategoryInfo : InvalidData: (:) [Find-VBRViEntity], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Command.FindVBRViEntity

    Get-Content : Cannot bind argument to parameter ‘Path’ because it is an empty string.
    At C:VeeamZIP.ps1:80 char:58
    + $EncryptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | Conver …
    + ~~~~~~~~~~~~~~
    + CategoryInfo : InvalidData: (:) [Get-Content], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.GetC
    ontentCommand

    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:VeeamZIP.ps1:81 char:40
    + $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $Comp …
    + ~~~
    + CategoryInfo : InvalidData: (:) [Start-VBRZip], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Commands.Backup.StartVBRZip

    You cannot call a method on a null-valued expression.
    At C:VeeamZIP.ps1:91 char:5
    + $TaskSessions = $ZIPSession.GetTaskSessions().logger.getlog().updatedrecords
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    • Max

      I got it to work, I forgot to set the Encryption to false and now it’s working flawlessly!! thanks so much for the script!

  • An Nguyen

    Thank to this great post, I have tried to convert it to multi-threading version. Seems that it works charm. I will add some comments and remove debug commands then upload it shortly. AN

  • An Nguyen

    Thank to this great post, I have tried to convert it to multi-threading version. Seems that it works charm. I will add some comments and remove debug commands then upload it shortly. AN

    • Brian Legg

      Did you ever upload your updated script?

  • Nathan

    Hello guys! It’s not working for me. I’m getting the following error:
    Coud you help me?

    Find-VBRViEntity : Unable to cast object of type ‘Veeam.Backup.Core.Infrastructure.CHvHostItem’ to type

    ‘Veeam.Backup.Core.Infrastructure.IViItem’.

    At C:UsersAdministratorDesktopVeeamZIP (updated).ps1:76 char:9

    + $VM = Find-VBRViEntity -Name $VMName -Server $Server

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo : NotSpecified: (:) [Find-VBRViEntity], InvalidCastException

    + FullyQualifiedErrorId : System.InvalidCastException,Veeam.Backup.PowerShell.Command.FindVBRViEntity

    Start-VBRZip : Cannot validate argument on parameter ‘Entity’. The argument is null. Supply a non-null argument and try the command

    again.

    At C:UsersAdministratorDesktopVeeamZIP (updated).ps1:86 char:40

    + $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $Comp …

    + ~~~

    + CategoryInfo : InvalidData: (:) [Start-VBRZip], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Commands.Backup.StartVBRZip

    You cannot call a method on a null-valued expression.

    At C:UsersAdministratorDesktopVeeamZIP (updated).ps1:91 char:5

    + $TaskSessions = $ZIPSession.GetTaskSessions().logger.getlog().updatedrecords

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : InvokeMethodOnNull

    Exception calling “Send” with “1” argument(s): “Failure sending mail.”

    At C:UsersAdministratorDesktopVeeamZIP (updated).ps1:113 char:1

    + $SMTP.Send($Message)

    + ~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : SmtpException

    • Geoffrey Wahonya

      I am getting the same error as Nathan. Any assistance would be great!

      • Vladimir Eremin

        It seems guys that you have Hyper-V deployements and meanwhile are trying to leverage VMware version of the script. Kindly, download and put into use the proper version (Hyper-V).

  • Bruno

    Hi! Thank you very much! It’s running perfectly!

    But the Hyperv script is wrong!!
    To work with Hyper-V you need to change “$VM = Find-VBRViEntity -Name $VMName -Server $Server” for “$VM = Find-VBRHvEntity -Name $VMName -Server $Server”

    Cheers!!

  • Matteo Simonelli

    Hi!!!

    First of all thank you very much for the script, it’s really useful!!

    It works fine for me if I launch it manually, but it does not if I schedule it within the task scheduler.
    I have installed the update 2b of Veeam Free and I have also installed the snapin.

    It’s difficult to debug it, because I get an empty email and so I have no idea where the issue is.
    I have also tried to print all the instruction in the script (to resolve the variable name and check what the script does in each step) but the file I get is empty too!!

    Do you have any ideas? The script run on a windows server 2012

    Thanks in advance for any help

    Ciao
    Matteo

    • Vladimir Eremin

      What happens if you execute script manually under the very same account? Or run it with the highest privileges?

      • Matteo Simonelli

        Hi Vladimir,

        thank you for you answer and sorry if I answwer so late!!!

        if I lauch it manually it works correctly and it creates the backup in the path set up in the script.
        I run it with the domain admin’s account

        Matteo

        • Vladimir Eremin

          Hard to say. Just for testing purpose – what happens if you select “Run with the highest privileges” option, will it help or not?

  • fpmeu Admin

    Hi all,
    when I run the ps1 script in Powershell I get errors:

    PS D:> .VeeamZIP.ps1
    Add-PSSnapin : Cannot add Windows PowerShell snap-in VeeamPSSnapin because it is already added. Verify the name of the
    snap-in and try again.
    At D:VeeamZIP.ps1:69 char:5
    + Asnp <<<< VeeamPSSnapin
    + CategoryInfo : InvalidArgument: (VeeamPSSnapin:String) [Add-PSSnapin], PSArgumentException
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

    You cannot call a method on a null-valued expression.
    At D:VeeamZIP.ps1:91 char:64
    + $TaskSessions = $ZIPSession.GetTaskSessions().logger.getlog <<<< ().updatedrecords
    + CategoryInfo : InvalidOperation: (getlog:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Could someone please tell me what´s wrong?
    I have backup file created in the path I defined in the script but I am affraid it could be corrupted somehow because of the error

    Many thanks in advance

    • fpmeu Admin

      maybe just use Poswrshell 3.0 instead of 2.0?

  • fpmeu Admin

    I run script and it looks like this in powershell console:
    PS D:> .VeeamZIP.ps1
    qlproxy4-amd64
    PS D:>

    in VeeamZIP.ps1 I have:
    $VMNames = “Nagios”;”qlproxy4-amd64″

    and in destination folder I can see oly backup of Nagios (also email notification contains only Nagios successful row). I do not understand why output in Poweshell console is qlproxy4-amd64. I also can not get the syntax for multiple VM to backup whitin one script. I am usinf quites for each name as well as semicolon (;) as separator (no spaces)

    Anybody with an idea?

    Many thanks in advance

    • fpmeu Admin

      problem seems to be solved.In script is written that semicolon is VM separator but it is not true and comma is.

      • Vladimir Eremin

        Yep, the description provided in the script is slightly wrong. The description provided in a blog post is right, though.

        # Names of VMs to backup separated by comma (Mandatory). For instance, $VMNames = “VM1”,”VM2”

  • fpmeu Admin

    Hi there,
    is there an option how to send notification email to more than one email address (so define more email addresses in the script)

    Thanks

    • Vladimir Eremin

      You should create a loop, within which more than one letter will be generated and sent.

      • CNealon

        Hi Vladimir, Can you explain on how to create this type of loop?

  • john3voltas

    Hello.
    Thanks to Rick who wrote this post and to Vladimir who wrote this script in the first place.
    I have tested the script, had similar issues to the ones already posted here and now I can say that it works fine for me.
    Just one question: this blog states that the script was updated on 5/18 but the one that I downloaded just right now states that it’s from 3/24 and it is has tiny bits that are different from the ones that are shown above.
    So, where exactly can I download the latest version?
    Thanks in advance

    • Vladimir Eremin

      Links have got mixed up slightly. The latest version for VMware can be downloaded: Download sample script for Hyper-V -> Open archive -> VeeamZIP (updated).ps1. We will fix the links soon, sorry for inconvenience.

      • Vladimir Eremin

        Links are fixed now. Check: Download sample script for VMware [Updated Sept 2015].

        • john3voltas

          Hi Vladimir. Thank you very much. 🙂

          • Vladimir Eremin

            Does the issue persist? I double checked everything at the time I wrote the last answer and links seemed to be ok. Can you try to refresh page, using ctrl+F5 combination.

        • john3voltas

          Well..that’s odd. The VMware script still looks a bit different from the snippet of the blog post and it still mentions a semi-colon between VM names instead of a coma…
          Besides it still says it’s from March instead of May?
          Could you please re-check it, Vladimir?

          Thanks in advance. 🙂

  • James Myers

    I was getting access denied message when trying to write to an external USB device. I tried a few things but eventually got working by opening services.msc and changing the VEEAM Backup Service to log on as domain admin account and not local system

  • Fando

    Hi
    Having an issue getting the script working for VMware, getting the following error
    Find-VBRViEntity : Cannot validate argument on parameter ‘Server’. The argument is null. Supply a non-null argument and try
    the command again.
    At C:VeeamNewVeeamZIP.ps1:76 char:48
    + $VM = Find-VBRViEntity -Name $VMName -Server $Server

    Stuck and not sure how to resolve this issue, any help would be great!!

    • Fando

      I have the script working but backing up to a local drive. I need the backup to output the file to a UNC path but this doesn’t seem to work. Is this possible?

      • Vladimir Eremin

        As mentioned below, check whether a computer account has write permissions on a share. Also, take a look at account specified for VB&R service (it might need to replaced with one having appropriate permissions).

    • Chora

      The $Hostname value has to match exactly the name given in VeeamZIP when you added the server (Under Infrastructure).
      So if you entered a fully qualified name when adding the server in VeeamZIP (e.g. server.domain.com) then this is the value you have to give to the $Hostname variable.
      Hope this clarifies the domain or not domain in the script.

    • Boštjan Cvelbar

      After upgrading it to powershell version 4, solved the issue

  • Rob D

    Hi
    I have been trying to make the Hyper-V script (VeeamZIP (HV – updated)) run with the free version of the software and have had no luck. I still receive the message:
    “Start-VBRZip : Veeam Backup Free Edition does not allow VeeamZIP of multiple VMs. Specify a single VM, or install a paid product license.”
    I had upgraded to version 2b and just recently removed and re-installed up to version 2b.
    Any help will be greatly appreciated.

    • Vladimir Eremin

      Seems like you’re trying to make VeeamZIP of multiple VMs at a time, which is prohibited in free version of software.

      • Rob D

        I guess I’m missing something. I had assumed that running the above script with the mentoned free version would work. I did only supply the script with one VM name though.

    • Rob D

      Today I was able to install the “non-R2” VMM client on the Veeam hosts and was able to backup a VM using the same script, just not a R2 VMM server with the R2 VMM client. Wierd.

  • Bruce

    Hi,

    I have installed “VeeamPSSnapin” via http://www.veeam.com/kb1489

    When I run the ps1 in windows 2012 standard, it is shown “Asnp : The Windows PowerShell snap-in ‘VeeamPSSnapin’ is not installed on this computer.”

    PS: The powershell is version 3.

    Please advise me how to work it out.

    Thank you in advance.

  • Martin Meduna

    Hi I am absolutly confused. This article is about veeam free edition. Why I receive error “Start-VBRZip : License is not installed.” and everybody on other forums explain that powershell is in paid version only…

  • CNealon

    Hi,

    FIrst of all let me thank you for this script. Works great. Only one issue I am having is changing the email notification addresses. I have altered the script but it does not seem to change the email addresses. Still uses the addresses that were in the script from first run.

    Any ideas?

    • Vladimir Eremin

      Have you tried to change variables in “# Notification Settings” section and try to run the script manually just to see whether the changed settings apply properly?

      • CNealon

        Yes, as for some reason they seem to be remaining the old way as if it does not take the variable a second time

  • Nick

    HELOO!!!Thank you!!!Can you help me? When i do back up in programm (no powershell) a can use CREDENTIAL for back up to LAN. Can i use it parameter in PowerSHELL?THANK YOU!!!

    • Vladimir Eremin

      Already answered in the corresponding thread on community forums. Kindly, take a look.

  • Stefano

    Hi,
    I have testing this solution with hyperv scritp.
    It work fine but the destination file is alway empty. In powershell there is not any errors…
    Any Ideas?

    • Andy Roadman

      Been having the same issue….

  • Andy Roadman

    What are the parameters for using the SMTP settings. Most require some sort of SSL usage and my work email wont allow it. was going to use my gmail to send it back to my work email. Any other suggestions?

  • Andy Roadman

    I have come up on another issue. I noted out the Encryption and Messaging components of the script to get past the errors, but when i run the script manually nothing happens except the command prompt opening for a few seconds. no new backups are created. any thoughts?

    • Andy Roadman

      figured this out. forgot to set some of the parameters to False.. Duh!!

  • moku

    Thank you for this. Been looking for a free solution that will solve all my needs and with this veeam is perfect…but just one question and I apologize if its obvious or already been answered but

    how do i use this to restore?

    I’ve made a backup using the script, but Im not sure how to use it once I have it because it doesnt show in Veeam…

    Thanks in advance.

    • moku

      Found the answer, and yes it is pretty simple.

      You have to import the backup into Veeam.

      Home -> Import Backup

      enter where you stored in and Wahlah!

  • disqus_N3A8ZSDA0Z

    I am trying to run this on over servers that are on a local network and back them up the a NAS. i can back them up fine to their local machine but when it attempts to backup to the NAs i get the following error:

    Error: The network name cannot be found.

    Cannot create folder. Folder path: [\*************VM_Backups].

    –tr:FC: Failed to create directory. Directory path: [\*************VM_Backups].

    –tr:Failed to call DoRpc. CmdName: [FcCreateDir].

    The network name cannot be found.

    Cannot create folder. Folder path: [\*************VM_Backups].

    • moku

      I had the same problem.

      The workaround I eventually got to work was to share the folder I wanted to save to and set the permissions on that folder to everyone, yeah I know not ideal but it worked.

      So my Directory path looks like \TargetMachineVM_Backups

      may not be what your looking for but hopefully it can lead you to what you need. And please post if you find something else that works for you.

  • Andy Roadman

    Thanks for the script. Very helpful.

    Can you elaborate or provide and example of the email notification setting?

    The servers/network I am setting this up for does not use exchange and so I was trying to use my Gmail account.

    using;
    smtp.gmail.com
    email TO and FROM is my email address @gmail.com
    added SMTPPort = “587”

    Cant seem to get this figured out.

    Thanks

  • CNealon

    Hi,
    Is there any way to get the summary also included in the email notifications?

    • Vladimir Eremin

      What information you think is missing in the resulting email? Duration, processing rate and bottleneck?

  • K Navatha

    Good article with excellent idea! I appreciate your post.Regards Sarkari Result

  • Charles

    Hello…when running the PowerShell script in Windows PowerShell ISE, I’ve noticed the following errors:

    cat : Cannot find drive. A drive with the name ‘ID’ does not exist.
    At C:VeeamZIPVeeamZIP.ps1:80 char:54
    + $EncryptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | Conver …
    + ~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (ID:String) [Get-Content], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetContentCommand

    Add-VBREncryptionKey : Cannot validate argument on parameter ‘Password’. The argument is null. Provide a valid value for the argument, and then
    try running the command again.
    At C:VeeamZIPVeeamZIP.ps1:80 char:53
    + $EncryptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | Conver …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidData: (:) [Add-VBREncryptionKey], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Command.AddVBREncryptionKey

    I have encryption enabled. I’m testing this but it seems to only happen if I have more than four VMs to backup in $VMnames. The email I receive after the job finishes says that the backups were successful. However, if I try a restore, nothing I enter for the encryption key prompt is accepted. So basically the restore is useless. Any ideas? Thanks

  • snarf attack

    I wanted a script that would backup all the Hyper-V hosts in my infrastructure, automatically enumerate the VMs on the host and backup all of them, except for a couple machines I don’t care about. I built on this one, and this is my end result:

    http://pastebin.com/tB8GnCbX

  • Timur Usmanov

    Hi. Thank you for you post. I’m trying to run VeeamZIP (VI – updated) script but has following error:

    Find-VBRViEntity : Cannot validate argument on parameter ‘Server’. The argument is null. Provide a valid value for the

    argument, and then try running the command again.

    At C:UsersAdministratordesktopVeeamZIP-VI-updatedVeeamZIP (VI – updated).ps1:76 char:48

    + $VM = Find-VBRViEntity -Name $VMName -Server $Server

    + ~~~~~~~

    + CategoryInfo : InvalidData: (:) [Find-VBRViEntity], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Command.FindVBRViEntity

    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:UsersAdministratordesktopVeeamZIP-VI-updatedVeeamZIP (VI – updated).ps1:86 char:40

    + $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $Comp …

    + ~~~

    + CategoryInfo : InvalidData: (:) [Start-VBRZip], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Commands.Backup.StartVBRZip

    You cannot call a method on a null-valued expression.

    At C:UsersAdministratordesktopVeeamZIP-VI-updatedVeeamZIP (VI – updated).ps1:91 char:5

    + $TaskSessions = $ZIPSession.GetTaskSessions().logger.getlog().updatedrecords

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo : InvalidOperation: (:) [], RuntimeException

    I checked the comments below but no one solution helped me… Could you please help me? Thank you.

    • Steve Hobday

      For email server requires authenication so added this line before the send

      $SMTP.Credentials = New-Object System.Net.NetworkCredential(“user@yourdomain.dom”, “password”)

  • Sijmen Denecker

    Hi, Vladimir.

    First of all let me say im loving the new functionality and the script.

    I must say this news came as a real joy. You know i was even using scheduled backups with Version 7 ? I did this with VMWare PowerCLI and 3 tasks per VM. First i make a snapshot with the powercli, then use the veeam scheduled file copy, then remove the snapshot with powercli. It was a real pain as the backups didnt always complete in the calculated time, even with margins. Also Veeamzip is faster then file copy.
    But we are buying the full blow version of Veeam next year for sure.

    Anywayz, i got a small question about this script.

    I want to backup mutiple VM’s with one ps1 script.

    But when i write $VMNames = “WGN09″;”WGN10” it only backups the first VM ? 🙁

    If i write $VMNames = “WGN09;WGN10” i get an error message. 🙁 (because the foreach only runs once with the full value)

    So what is the correct syntax please ?

    (Another nice addition is Start-Transcript -Path “C:xxx.log” to get some logging)

    Kind Regards,

    Sijmen

    • Sijmen Denecker

      Anyone ? Please ?

    • Sijmen Denecker

      I found the answer myself in some other post in the Veeam forums. Altought the script states “Names of VMs to backup separated by semicolon (Mandatory)” it only works after using normal commas.

      So now i have $VMNames = “WGN09″,”WGN10” and its working.

  • Larmire

    How would I authenticate to my SMTP server?

  • Alexander

    I have the same question as Larmire. How would I authenticate to my SMTP server?

  • Nilz

    Can anyone tell me how I (as an personal/home user), with ~5-10 VM’s in hyper-v, should achieve a “good” backup-strategy?
    Free is good, but the problem with veeam-zip (even tho I now can automate it), always creates a full backup…..
    Without incremental backup, I get ~50 gigs of files -every- time i run this….
    So… what to do? Let’s say I want 1 backup per day, thats 350 gigs of files to store offsite per week….

    So, what have I missed? Is it impossible to use veeamzip in a continuous way? No incremental support?
    Full-veeam has everything I want, but it’s impossible to pay up as a home user / enthusiast… There does not seem to be any “personal” / “home” licenses?

    • Rick Vanover

      Hi Nilz: For personal/home, you should look at the NFR license for labs. It’s made for those situations and it is a fully functional version of Veeam Availability Suite, so you’ll have the proper scheduler and incremental backups.

      http://go.veeam.com/free-nfr-veeam-availability-suite

  • Shawn Griffin

    I’d be interested in this working, but i have not seen anyone address this issue? or if its because Hyper-V over VMware….

    Find-VBRViEntity : Cannot validate argument on parameter ‘Server’. The argument is null. Provide a valid value for the

    argument, and then try running the command again.

    At C:VeeamZIP.ps1:76 char:48

    + $VM = Find-VBRViEntity -Name $VMName -Server $Server

  • Shawn Griffin

    EDIT: I got this working shortly after posting.
    Find-VBRViEntity : Cannot validate argument on parameter ‘Server’. The argument is null
    for me this translated to can’t find my hyper-v host because i was using the fqdn. (I found in a different post someone else had this. Removed the domain to make it just servername and started working immediately.

    • Rick Vanover

      Cheers, Shawn – thanks for sharing.

  • Shawn Griffin

    So tried this on a second hyper-V and hitting a snag. Error=
    Start-VBRZip -Entity $VM -Folder $Directory cannot validate argument on ‘Entity’ argument is null What is $VM that is coming back as null?

  • Janne Saarinen

    Hi, does this script (for HyperV) work with new version 9 too?

    • Rick Vanover

      Not positive – but that is motivation for me to update the post!

  • Boštjan Cvelbar

    I recieve this error:
    Find-VBRHvEntity : Unable to find assembly ‘Veeam.Backup.HVLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bfd684
    de2276783a’.
    At C:scriptsBackup-Virtual-Machines-On-HypervOBIWAN.ps1:78 char:25
    + $VM = Find-VBRHVEntity <<<< -Name $VMName -Server $Server
    + CategoryInfo : NotSpecified: (:) [Find-VBRHvEntity], SerializationException
    + FullyQualifiedErrorId : System.Runtime.Serialization.SerializationException,Veeam.Backup.PowerShell.Command.Find
    VBRHvEntity

    Start-VBRZip : Cannot validate argument on parameter 'Entity'. The argument is null. Supply a non-null argument and try
    the command again.
    At C:scriptsBackup-Virtual-Machines-On-HypervOBIWAN.ps1:88 char:39
    + $ZIPSession = Start-VBRZip -Entity <<<< $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!
    $EnableQuiescence) -AutoDelete $Retention
    + CategoryInfo : InvalidData: (:) [Start-VBRZip], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Commands.Backup.StartVBRZip

    i am able to make backup thru GUI, but not thru PowerShell script after upgrading veeam backup and replication from 8 to version 9.
    PLEASE HELP

    • Rick Vanover

      Hi Bostjan: I’d share this in the PowerShell Forum at forums.veeam.com…

  • Aizudin AY

    For email with notifications with authentication, I am using this & it is currently working as expected. You’ll need to edit the lower portion of the script..

    If ($EnableNotification)
    {
    $Message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo
    $Message.Subject = $EmailSubject
    $Message.IsBodyHTML = $True
    $Message.Body = $MesssagyBody | ConvertTo-Html -head $style | Out-String
    $SMTP = New-Object Net.Mail.SmtpClient($SMTPServer)
    $SMTP.Port = 587
    $SMTP.Credentials = New-Object System.Net.NetworkCredential(“username@domain.com”, “yourPasswordHere”);
    $SMTP.EnableSsl = $True;
    $SMTP.Send($Message)
    }

  • Doug B

    Script works when email is disabled but when I enable email it generates a series of errors starting with this


    New-Object : Exception calling “.ctor” with “2” argument(s): “Value cannot be null.
    Parameter name: from”

    At C:Usersadministrator.xxxDocumentsveeamzip.ps1:109 char:12
    + $Message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationEx
    ception
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.
    Commands.NewObjectCommand

    The property ‘Subject’ cannot be found on this object. Verify that the property
    exists and can be set.

    Any tips or help would be great

    • Polina Vasileva

      ?approve

      Polina Vasilyeva
      writer | Veeam Software polina.vasilyeva@veeam.com

    • Vladimir Eremin

      You don’t seem to provide the required variables with needed values. Thus, value cannot be null error.

  • Hil Al

    I’m trying to use this script to a Synology NAS but I am getting an access denied error message, backing up to C: works with no problem, the logged in user can browse the mapped drive or the UNC path, either way specified in the script does not work and returns the following error; “The system cannot find the path specified. Failed to create or open file Z:[backup-filename].vbk”

    I tried setting the service to run as the logged in user that has access to the share but no joy, any ideas?

    • Vladimir Eremin

      This question has been discussed here and on our forums several times already. Kindly, check previous answers. (computer account lacking required write permissions, etc.)

      Thanks.

  • Mikael

    Im getting this message in the details coloumn in the email after finished backup and was wondering if this if the correct output or if something is wrong? Success: Creating snapshot Microsoft Software Shadow Copy provider 1.0 (mode: Crash consistent)

    Would be great if anyone can confirm this is correct so i can sleep comfortably !

    • Vladimir Eremin

      Confirmed. The said message just means that crash consistent snapshot (the same as it would be after a power outage) has been taken on the given VM.

  • https://www.techandme.se Daniel Hansson

    Hi, thanks for a great script! I’m new to Powershell and get this:

    ############################
    Get-Content : Cannot bind argument to parameter ‘Path’ because it is an empty string.
    At C:UsersDanielDocumentsVeeamZIP.ps1:80 char:58
    + … ptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | Conve …
    + ~~~~~~~~~~~~~~
    + CategoryInfo : InvalidData: (:) [Get-Content], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.
    ontentCommand

    Start-VBRZip : Cannot bind parameter ‘EncryptionKey’. Cannot convert the “” value of type “System.String”
    m.Backup.PowerShell.Types.PSCryptoKey”.
    At C:UsersDanielDocumentsVeeamZIP.ps1:81 char:169
    + … nableQuiescence) -AutoDelete $Retention -EncryptionKey $EncryptionKey
    + ~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Start-VBRZip], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Veeam.Backup.PowerShell.Commands.Backup.Star

    You cannot call a method on a null-valued expression.
    At C:UsersDanielDocumentsVeeamZIP.ps1:91 char:5
    + $TaskSessions = $ZIPSession.GetTaskSessions().logger.getlog().upd …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    ############################

    What seems to be the issue here? I’m great with Linux CLI, but this is Greek to me.

    Thank you in advance!

    • https://www.techandme.se Daniel Hansson

      Solved it by setting Encryption to $False

  • https://www.techandme.se Daniel Hansson

    I have an issue regarding sending the Veeam backup files to a NAS in the same subnet in Powershell. I have mounted the NAS in Windows (on the PC that has Veeam installed, 192.168.1.110) as a Network Drive, and I can login and view the files if I use the standard File Explorer, but with Powershell I can’t write to that NAS directory. The DIR I use for storing backups is “veeam” on the NAS, like this:

    $Directory = “\192.168.1.115veeam”

    It works if I do it from the GUI, but with Powershell it fails. I think it’s becuase it needs permission (the share is password protected and I can’t change that) in form of login credentials. I also tried to give “Guest” full access on the NAS, but no luck there either. In Linux it would be easy, just create a password file or something and then use that credentials, but in Powershell I don’t have a clue. I tried a few things already though, keep reading.

    When I do “Get-PSDrive” in Powershell, the Network Drive shows up as “Q” which is Q: on my Windows system that is assigned to the Network Drive in Windows.

    I have also tried to remove Q: as a Network Drive and remount it within Powershell (don’t know if that would make a difference, but I was thinking that Powershell maybe caches the password in a different way than if I do it in Windows GUI?) with this command:

    New-PSDrive -Name Q -PSprovider Filesystem -Root \192.168.1.115veeam -Credential VEEAM_NAS -Persist

    But it fails as it says “Multiple connections to a server or shared resource by the same user, using more than one user name are not allowed. Disconnect all previous connections to the server or shared resource and try again” and can’t create a new PSDrive. Because of this I tried to remove all the Shared Storages with “net use * /delete” but it says that “The list is empty” aka no Shared Storages. So it shouldn’t be a problem to create a new drive, but it is.

    I have also tried to change IP on the NAS so that Windows would think it’s a new Storage, but that didn’t work either. I also checked all the shared resources in services.msc but nothing was shared there either. I have also tried to flush DNS and renew DHCP, but no luck. So in other words, it says that I have shared resources but I don’t.

    And yes, I rebooted both the NAS and the Windows machines several times.

    I’m stuck! As I see it there are a couple of options that I haven’t tried yet:

    1. Re-format the Windows PC (192.168.1.110) to clean up everything and start over
    2. Maybe Veeam uses the same credentials as in Windows(?), and therefore change the NAS user to the same user as in Windows, also with the same password ofc.

    The NAS is a QNAP 269 Pro Turbo, and the Windows Machine is Windows 10 Pro clean install.

    Should I enter some additional $Variable to the script to get this working, or do you have some other suggestion? Please help!

  • Boštjan Cvelbar

    How to make script send you notification only in case where backup did not succeded. Currently script sends reports in both cases (sucess & failure).

    • Vladimir Eremin

      You will have to check whether there is at least one failed or warning status in the task sessions and form and send email, only in case of positive answer.

  • CNealon

    Is it possible to have selective notifications from the script? On warning and failure. So we only get the mails if there is an issue.

  • CNealon

    Hi,

    The autodelete function is not working at all for use. The rest of the script is working perfectly. Any ideas? Currently we are deleting the backups manually each day
    Thanks in advance
    Caoibhin

    • Vladimir Eremin

      Isn’t there an typo by any chance?

      I’ve got similar complain recently, and it’s turned out to be a mistake made while modifying original script.

      https://forums.veeam.com/post220518.html#p220518

      Thanks.

      • CNealon

        Not that I can see.

        # Author: Vladimir Eremin
        # Created Date: 3/24/2015
        # http://forums.veeam.com/member31097.html
        #

        ##################################################################
        # User Defined Variables
        ##################################################################

        # Names of VMs to backup separated by comma (Mandatory). For instance, $VMNames = �VM1�,�VM2�
        $VMNames = “Servername”

        # Name of vCenter or standalone host VMs to backup reside on (Mandatory)
        $HostName = “HostServer”

        # Directory that VM backups should go to (Mandatory; for instance, C:Backup)
        $Directory = “C:Backups”

        # Desired compression level (Optional; Possible values: 0 – None, 4 – Dedupe-friendly, 5 – Optimal, 6 – High, 9 – Extreme)
        $CompressionLevel = “5”

        # Quiesce VM when taking snapshot (Optional; VMware Tools are required; Possible values: $True/$False)
        $EnableQuiescence = $True

        # Protect resulting backup with encryption key (Optional; $True/$False)
        $EnableEncryption = $False

        # Encryption Key (Optional; path to a secure string)
        $EncryptionKey = “”

        # Retention settings (Optional; By default, VeeamZIP files are not removed and kept in the specified location for an indefinite period of time.
        # Possible values: Never , Tonight, TomorrowNight, In3days, In1Week, In2Weeks, In1Month)
        $Retention = “In1Week”

        ##################################################################
        # Notification Settings
        ##################################################################

        # Enable notification (Optional)
        $EnableNotification = $True

        # Email SMTP server
        $SMTPServer = “smtp.company.com”

        # Email FROM
        $EmailFrom = “veeam1@company.com”

        # Email TO
        $EmailTo = “veeam2@company.com”

        # Email subject
        $EmailSubject = “Veeam Report:”

        ##################################################################
        # Email formatting
        ##################################################################

        $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: #dddddd; padding: 5px; }”
        $style = $style + “TD{border: 1px solid black; padding: 5px; }”
        $style = $style + “”

        ##################################################################
        # End User Defined Variables
        ##################################################################

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

        $Server = Get-VBRServer -name $HostName
        $MesssagyBody = @()
        foreach ($VMName in $VMNames)
        {
        $VM = Find-VBRHvEntity -Name $VMName -Server $Server

        If ($EnableEncryption)
        {
        $EncryptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | ConvertTo-SecureString)
        $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention -EncryptionKey $EncryptionKey
        }

        Else
        {
        $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention
        }

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

        if ($FailedSessions -ne $Null)
        {
        $MesssagyBody = $MesssagyBody + ($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
        {
        $MesssagyBody = $MesssagyBody + ($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 = $MesssagyBody | ConvertTo-Html -head $style | Out-String
        $SMTP = New-Object Net.Mail.SmtpClient($SMTPServer)
        $SMTP.Send($Message)
        }

  • zis

    Hi I am currently on version 9.0.0.175 and the script is working just fine. I would like to update to version 9.5, can anyone verify that the script is also compatible with this version?

    • Vladimir Eremin

      Yes, it is.

      • zis

        Thank you for the quick reply Vladimir and a huge thank you for your awesome script it has really made my life easier 🙂

  • Jeff Scharfenberg

    This works pretty well! I had to modify the emailing portion since i’m using gmail but that wasn’t too hard. The only part that doesn’t work, which is just a small part, is the email body comes as the code, not an actual html. Any ideas on formatting that?

    • Vladimir Eremin

      The script above is supposed to convert a body to HTML (see $Message.IsBodyHTML = $True parameter). Chances are, there are some peculiarities caused by usage of gmail that need to be addressed differently.

      I’d recommend checking different approaches regarding email body conversion and seeing whether a different method work for you.

  • Michal

    Hi

    Is AutoDelete option really work?
    I schedule my script once a week on sunday:

    $Retention = “Tonight”
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -AutoDelete $Retention

    but old backup was never delete. I try “In3days” and “In1Week” and still the same.

    • Vladimir Eremin

      The said option should work without issues. The only issue reported about it turned out to be a typo.

      However, I will try to confirm this problem, once I have a spare time.

  • Jan Ol

    Hi, i got also an error with auto-delete through the $Retention variable. It doesn’t work since updating Veeam to version 9.5.
    The script has not been modified.

    • Vladimir Eremin

      I’ve checked it with 9.5 Update 1, and haven’t been able to reproduce it.

      I’d appreciate, if you could update to U1 first and, then, double check whether VeeamZIP retention works for both GUI and PowerShell.

      • Jan Ol

        Hi, thanks for replying.
        I already updated to 9.5 Update 1 a few days ago, but retention via Powershell does still not work. I have also rebooted the server Veeam and Hyper-V is running on after that.
        Will test via VeeamZIP and have to wait until rentention trigger fires (tonight, tommorrow)

        • Vladimir Eremin

          Strange.

          I’ve asked QA team to investigate it closely.

          I will post back once I have more information.

      • Jan Ol

        Hi,
        Now I can confirm that retention works with VeeamZIP, but still not via PowerShell. I assume retention in VeeamZip was working all the time but haven’t used it.