Veeam Backup Free Edition: Now with PowerShell!

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 can 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 the 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:

Get weekly blog updates
By subscribing, you are agreeing to have your personal information managed in accordance with the terms of Veeam’s Privacy Policy
Cheers for trusting us with the spot in your mailbox!
Now you’re less likely to miss what’s been brewing in our blog with this weekly digest.
OK
NEW
V11

Eliminate Data Loss
Eliminate Ransomware

#1 Backup and Recovery

157 Comments

  • Greg Zartman says:

    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 says:

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

  • Manuel says:

    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.

  • Manuel says:

    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

  • Aurélien says:

    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 says:

    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.).

  • Manuel says:

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

  • Vladimir Eremin says:

    Try to check whether the given computer account has write permission on a given share.

    http://forums.veeam.com/powershell-f26/discussion-on-blog-post-update-2-featuring-powershell-t28023-15.html#p149539

  • Ryan Lee says:

    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.

  • Ryan Lee says:

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

  • Aurélien says:

    Hi, I have added my computer account on the share / folder security with write permission and it’s working now ! Thanks for this workaround !

  • Vladimir Eremin says:

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

  • Vladimir Eremin says:

    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.

  • Ryan Lee says:

    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!

  • Martin says:

    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 says:

    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 says:

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

  • Vladimir Eremin says:

    You should use Out-File or similar commandlets.

    https://technet.microsoft.com/en-us/library/hh849882.aspx

  • Pete says:

    Thank you Vladimir I figured that out shortly after posting and got it working using the Out-File command.

  • Max says:

    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 says:

    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 says:

    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 says:

    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

  • Nathan says:

    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 says:

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

  • Vladimir Eremin says:

    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).

  • Brian Legg says:

    Did you ever upload your updated script?

  • Bruno says:

    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 says:

    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 says:

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

  • Matteo Simonelli says:

    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

  • Aleks says:

    Hi,
    how i can install this snap-in?

  • Vladimir Eremin says:

    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.

  • Vladimir Eremin says:

    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 says:

    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 says:

    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 says:

    maybe just use Poswrshell 3.0 instead of 2.0?

  • fpmeu Admin says:

    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

  • fpmeu Admin says:

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

  • john3voltas says:

    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 says:

    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”

  • Vladimir Eremin says:

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

  • Vladimir Eremin says:

    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 says:

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

  • john3voltas says:

    Hi Vladimir. Thank you very much. :)

  • john3voltas says:

    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. :-)

  • Vladimir Eremin says:

    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.

  • James Myers says:

    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 says:

    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!!

  • Rob D says:

    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.

  • Fando says:

    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 says:

    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).

  • Vladimir Eremin says:

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

  • Rob D says:

    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.

  • Bruce says:

    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.

  • Rob D says:

    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 says:

    After I reinstall(it is shown repaired/uninstall, I chose “repaired”) “VeeamPSSnapin”, reboot it and reinstall Update 2B, reboot it again. Now it works.

  • Martin Meduna says:

    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 says:

    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?

  • Nick says:

    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 says:

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

  • Vladimir Eremin says:

    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?

  • Vladimir Eremin says:

    Under certain circumstances re-installation of Update 2B along with VB&R PS

    snap-in might be indeed required.

    http://forums.veeam.com/powershell-f26/discussion-on-blog-post-update-2-featuring-powershell-t28023-30.html?hilit=update%20install#p158425

    Glad to hear that you’ve figured it out already.

  • CNealon says:

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

  • Stefano says:

    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 says:

    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 says:

    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 says:

    Been having the same issue….

  • Andy Roadman says:

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

  • CNealon says:

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

  • moku says:

    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.

  • disqus_N3A8ZSDA0Z says:

    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].

  • Andy Roadman says:

    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

  • moku says:

    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.

  • moku says:

    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!

  • CNealon says:

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

  • Vladimir Eremin says:

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

  • K Navatha says:

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

  • Charles says:

    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 says:

    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 says:

    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.

  • Sijmen Denecker says:

    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 says:

    Anyone ? Please ?

  • Larmire says:

    How would I authenticate to my SMTP server?

  • Sijmen Denecker says:

    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.

  • Alexander says:

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

  • Nilz says:

    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 says:

    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

  • Alexander says:

    :-) And what about free version of VBR and powershell?

  • Shawn Griffin says:

    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 says:

    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 says:

    Cheers, Shawn – thanks for sharing.

  • Shawn Griffin says:

    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?

  • Rick Vanover says:

    Interesting – I’ll let Vlad know. Are you using v9 yet?

  • Vladimir Eremin says:

    Aren’t you trying to VeeamZIP VMs to a backup repository, using free
    VB&R edition? If so, be aware that it’s not allowed and you should
    use folder parameter instead.

    https://forums.veeam.com/powershell-f26/upgrade-to-v9-t32925.html?hilit=neither%20repository#p180127

  • Janne Saarinen says:

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

  • Rick Vanover says:

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

  • Chora says:

    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 says:

    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

  • Boštjan Cvelbar says:

    After upgrading it to powershell version 4, solved the issue

  • Rick Vanover says:

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

  • Aizudin AY says:

    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 says:

    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 says:

    ?approve

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

  • Hil Al says:

    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 says:

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

  • Vladimir Eremin says:

    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 says:

    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 says:

    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.

  • 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!

  • Solved it by setting Encryption to $False

  • 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 says:

    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 says:

    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 says:

    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 says:

    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 says:

    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.

  • zis says:

    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 says:

    Yes, it is.

  • zis says:

    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 says:

    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?

  • Michal says:

    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.

  • CNealon says:

    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)
    }

  • Vladimir Eremin says:

    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.

  • Vladimir Eremin says:

    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 says:

    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.

  • Steve Hobday says:

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

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

  • Vladimir Eremin says:

    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 says:

    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)

  • Jan Ol says:

    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.

  • Vladimir Eremin says:

    Strange.

    I’ve asked QA team to investigate it closely.

    I will post back once I have more information.

  • Alex Saenz says:

    This saved me. Thanks!

  • LilRhody says:

    Hi. I was able to get this working with your great article here so THANK YOU! One question though, I’m using your encryption method where it uses a secure string. When I had to reinstall Veeam on a new machine I thought I could just copy over my old securestring.txt file but Veeam threw an error so I had to redo the encryption part to generate a new key.
    This got me thinking, my Veeam PC backs up to an external HD, what if my Veeam PC blows up and I need to reinstall it on a new machine? Will the new PC be unable to access my backups because it wasn’t the PC that originally generated the key?

  • Vladimir Eremin says:

    On a new PC you will need to install backup server first. Then, import encrypted backups. While importing them, you will be asked to input corresponding encryption key. There should not be any issues, as long as you remember it.

    That’s the way it should work, but you might want to verify it in order to feel confident, when disaster comes.

  • LilRhody says:

    Ok, got another question. I set this whole process up, including generating the encryption key, under my admin login. I then created my scheduled task and set it to use my admin account that is just used to run services and things like this. The job runs then immediately says it’s finished and doesn’t create the backup IF the scheduled task is running as anyone other than my own admin account. If I set the encryption variable to “False” in the script it will then run under any login. Domain Admins have full rights to the folder and files where the securestring.txt file is stored, any idea why it won’t work for any login except mine?

  • Vladimir Eremin says:

    Chances are, encryption key generated by one account cannot be used by different ones. You can double check it on MS PS communities.

  • Doug Fergusson says:

    Thanks Bruno for the amendment! & thanks Vladimir Emrin for creating. For anyone pointing to a network share, I’ve had success changing the “VEEAM Data Mover” service to run with the network share credentials, and also adding the NAS as a backup Repository. You can do this by selecting view, fully functionality (advanced) and adding. You can change back to free after, and still works.

  • Will Miller says:

    Hi,
    I installed veeam 9.5 v1 to evaluate last week, and found it was missing scheduling also, which nearly had pushed me to using altaro instead.. .
    However after hearing v2 has scheduling, as shown in this discussion, i deided to re evaluate…
    however for the life of me i cannot find where to download a complete version of v2 from, and when logged into veeam if i click on the update dwnload i get redirected back to veeam main page.,, can any one point me where i can download v2 from pls
    cheers
    ..

  • Govinda Naik says:

    Where I can find Powershell Version 4? Please share the location.

  • Govinda Naik says:

    Hi,

    I have tried script provided by you but I am getting below error. I have mentioned correct Vcenter name as FQDN but still getting error. Please suggest.

    PS C:Veeam Script> C:Veeam ScriptVeeamZIP (VI – updated).ps1

    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:Veeam ScriptVeeamZIP (VI – updated).ps1:77 char:48

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

    + ~~~~~~~

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

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

  • LilRhody says:

    Hi one more question. I am using this method to back up my VM’s and I rotate between 2 USB drives every week but the retention settings don’t seem to work across multiple USB drives. For example if drive A has been sitting offsite for a week and I plug it into my Veeam PC it does not remove older files on that drive, it only seems to work if I just leave 1 drive plugged in all the time which I can’t do. Should the script simply be looking at ANY file in the folder that is older than 1 week and remove them?

  • Vladimir Eremin says:

    Number of issues have been reported in regards to retention. We conducted numerous tests and failed to confirm the issue. Can you try to apply retention settings via GUI and see whether it works or not?

  • Vladimir Eremin says:

    It means that $Server variable is null. Check how the variable is assigned, and whether the variable returns anything. Chances are, the server with the provided name does not exist or is not added to backup server. Thanks.

  • Deniel Wijaya says:

    First of all, thank you for this awesome product and awesome script, this really helps a lot. Having said that, I run into some minor bug when running the script with encryption, I got the following error

    “cat : Cannot find drive. A drive with the name ‘ID’ does not exist.
    At E:BackupBackup ScriptVeeamZip.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 E:BackupBackup ScriptVeeamZip.ps1:80 char:53
    + $EncryptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | Conver …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidData: (:) [Add-VBREncryptionKey], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.AddVBREncryptionKey”

    I notice that the error does not happen on the first VM and only happens on the 2nd and so forth, and upon further inspection I notice the error relates to the $EncryptionKey parameter, so here’s how to fix this : move the following line
    $EncryptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | ConvertTo-SecureString)
    from inside the foreach looping to before the loop. That should do it

    $Server = Get-VBRServer -name $HostName
    $MesssagyBody = @()
    $EncryptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | ConvertTo-SecureString)

    foreach ($VMName in $VMNames)
    {
    $VM = Find-VBRViEntity -Name $VMName -Server $Server

    If ($EnableEncryption)
    {

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

  • BB says:

    How do give write permissions to share folder?
    You mean give the veeam backup server administrator to the share folder?

  • Kieran says:

    Thanks for the script, works great!

    Having an issue where all my backups are deleted at the end of the script. Retention policy is set to 2 weeks.

    No idea what is going on…

  • Vladimir Eremin says:

    Try to set retention policy outside of PowerShell – GUI. If the issue is reproduced, collect debug logs and open a ticket with our support team.

  • Josh Almeida says:

    Is there any way to use a retention period that is not listed? For example can I use “In5Days” instead of In3Days? I want as many days worth of backups as I can fit but my drive can’t hold an entire weeks worth. If I set it to In3Days I end up with only 2 backups on the drive because they get rotated weekly. Also it seems like if I plug a drive in that has older backups on it the retention does not remove them, they stay indefinitely. I thought the script would look for any file date older than specified but it only seems to remove backups IT created while that drive is plugged in, once you unplug it then re-use it won’t delete those older files.

  • Josh Almeida says:

    If we are using powershell to do all the scripting for the job how do we alter retention in the GUI?

  • Vladimir Eremin says:

    You’re talking about VeeamZIP backups, right? If so, be aware that currently there is a known issue with how PS sets retention for such backups. The issue will be addressed in the upcoming Update 3.

  • Sean Bond says:

    I have been using this script for a few years now, and its great!

    Is there any way to use SMTP authentication? I use Sendgrid and Office365, however both of those require auth

  • Fabius says:

    add this variables in the “notification settings” section:

    # Enable notification (Optional)
    $EnableNotification = $True
    # Email SMTP server
    $SMTPServer = “”
    # SMTP port
    $SMTPport = “”
    # SMTP use SSL
    $SMTPssl = $False
    # SMTP user for authentication
    $SMTPuser = “”
    # SMTP password for authentication
    $SMTPpass = “”
    # Email FROM
    $EmailFrom = “”
    # Email TO
    $EmailTo = “”
    # Email subject
    $EmailSubject = “”

    and change the sending code at the bottom of the script as follow:

    $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, $SMTPport)
    $SMTP.EnableSsl = $SMTPssl
    $SMTP.Credentials = New-Object System.Net.NetworkCredential($SMTPuser, $SMTPpass);
    $SMTP.Send($Message)

  • Sean Bond says:

    Fantastic! That works great. Thanks

    Is there any way around storing the password in plaintext?

  • Fabius says:

    open a powershell console and run:
    $pw = Read-Host -AsSecureString

    now digit your password and hit enter, when the prompt come back run:
    $encpw = ConvertFrom-SecureString -SecureString $pw

    then digit $encpw and hit enter, a very long string should appear, copy it and in your script use:
    $secureString = “my-very-long-encrypted-string”
    $SMTPpass = ConvertTo-SecureString $secureString

  • Avijit Dutta says:

    Hello All – I am using Samba Network Share. how to do the backup in that shared path. When i am taking backup from GUI, it is completed successfully, but that try to use powershell, its given me below errors.
    1) when using direct UNC path – Error: The user name or password is incorrect. Failed to process [isFileExists].
    2) When doing the Map Network Drive – Error: Failed to call RPC function ‘FcCreateDir’: The system cannot find the path specified. CreateDirectory(v:Infra_Backup) function call failed. Cannot create folder. Folder path: [v:Infra_Backup]. Cannot create folder. Folder path: [v:Infra_BackupBackup_OVF]. Cannot create folder. Folder path: [v:Infra_BackupBackup_OVFLAMP]. Could not perform threshold check for backup location “v:Infra_BackupBackup_OVFLAMP” due to space info retrievement fail!

    Please suggest.

Leave a Reply

Your email address will not be published.