PowerShell script exchange
david.matthewson
Influencer
Posts: 10
Liked: 1 time
Joined: Oct 08, 2018 3:37 pm
Full Name: D K Matthewson
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by david.matthewson »

Hi - not so much an answer as a request for help with running PS scripts to manage the Free version.

I've been using one of Vladimar's sample scripts to backup a few VMs on a dev system and it works well. I have now copied the script and and trying to use it on a home lab, but it fails. The versions of B&R seem to be the same - 9.5.0..1922.

The script returns these errors:

Code: Select all

------------------------------------------------------------------------------------------------------------------
PS C:\Scripts\Veeam> C:\Scripts\Veeam\WM-WM-DC01.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:\Scripts\Veeam\WM-WM-DC01.ps1:76 char:48
+   $VM = Find-VBRViEntity -Name $VMName -Server $Server
+                                                ~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Find-VBRViEntity], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.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:\Scripts\Veeam\WM-WM-DC01.ps1:86 char:40
+     $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compre ...
+                                        ~~~
    + CategoryInfo          : InvalidData: (:) [Start-VBRZip], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.StartVBRZip
-------------------------------------------------------------------------------------------------------------------------
and the script looks like this - which is, I think, 'standard' apart from the variable values.

# 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 = "WM-DC01"

# Name of vCenter or standalone host VMs to backup reside on (Mandatory)
$HostName = "LL-ESX01.IMCUK.net"

# Directory that VM backups should go to (Mandatory; for instance, C:\Backup)
$Directory = "\\NAS-02\DiskImages\imcuk\Veeam\WM-DC01"

# 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 = $False

# 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 = "TomorrowNight"

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

# Enable notification (Optional)
$EnableNotification = $False

# Email SMTP server
$SMTPServer = "wm-ap01.imcuk.net"

# Email FROM
$EmailFrom = "alerts@IMCUK.net" 

# Email TO
$EmailTo = "alerts@IMCUK.net"

# Email subject
$EmailSubject = "WM Veeam Backup"

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

$style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$style = $style + "TD{border: 1px solid black; padding: 5px; }"
$style = $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-VBRViEntity -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)
}

----------------------------------------------
esx is S 5.5, names are 'pingable' and the jobs run fine 'by hand' via the B&R GUI, but fail under PS.

What am I doing wrong pls!??

Thanks

David
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Kindly, check the answers provided previously. The root cause for the issue experienced has been covered multiple times already. Thanks!
david.matthewson
Influencer
Posts: 10
Liked: 1 time
Joined: Oct 08, 2018 3:37 pm
Full Name: D K Matthewson
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by david.matthewson »

Thanks for the prompt reply. I can't test this out right now as a long GUI test backup is running currently but I tried another (simpler) script of yours ..

Code: Select all

$VMName = "Name of your VM"
$HostName = "Name of ESXi or vCenter server"
$Directory = "Name of target directory"
$Server = Get-VBRServer -name $HostName
$Server
$VM = Find-VBRViEntity -Name $VMName -Server $Server
$VM
Start-VBRZip -Entity $VM -Folder $Directory
and that worked fine.

I suspect perhaps that the Veeam snapin was not being loaded - Asnp VeeamPSSnapin.

I'll fully test this later tonight - many thanks.
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

The message above suggests that $Server variable has not been assigned properly. Make sure vCenter or ESXi host VMs reside on is added to a backup console and you refer to it within a code, using the exact same name (as the one under which it's added to a backup console). Thanks!
david.matthewson
Influencer
Posts: 10
Liked: 1 time
Joined: Oct 08, 2018 3:37 pm
Full Name: D K Matthewson
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by david.matthewson »

Doh! Total idiot that I am.. yes, of course you are 100% correct. I had been 'clever' and specified the FQDN as in servername.com instead of EXACTLY what the GUI inventory was showing me - viz: 'servername'

Change that and it all works - thanks again for your help and a brilliant product.
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

You're welcome. Should other help with scripting be needed, don't hesitate to reach me. Thanks!
david.matthewson
Influencer
Posts: 10
Liked: 1 time
Joined: Oct 08, 2018 3:37 pm
Full Name: D K Matthewson
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by david.matthewson » 1 person likes this post

Much appreciated - fantastic support!
mkaec
Veteran
Posts: 465
Liked: 136 times
Joined: Jul 16, 2015 1:31 pm
Full Name: Marc K
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by mkaec »

I have a couple of Hyper-V VMs that were getting skipped over. The email notification was reporting success for them, however.

When I looked closer, I noticed that the VMs being skipped have brackets in their names. Example:

Code: Select all

Windows 7 Test [2015]
Windows 7 Test [2018]
When I manually run Find-VBRHvEntity, nothing is returned. Example:

Code: Select all

Find-VBRHvEntity -Name 'Windows 7 Test [2018]' -Server HYPERVHOST.domain.local
So, it looks like the brackets are indeed causing an issue.

I was able to work-around by changing the line:

Code: Select all

$VM = Find-VBRHvEntity -Name $VMName -Server $Server
to

Code: Select all

$VM = Find-VBRHvEntity -Server $Server | Where {$_.Name -eq $VMName}
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

You're spot on - name parameter processes incorrectly string that contains brackets. Thank you for updating the topic with the found resolution; appreciated!
mkaec
Veteran
Posts: 465
Liked: 136 times
Joined: Jul 16, 2015 1:31 pm
Full Name: Marc K
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by mkaec »

It really bothered me that the email was showing success for the skipped VMs. I only found this because I reviewed the vhdx files and noticed that the corresponding rct files had never been created. It could have been bad if this had been discovered due to a need to recover.

To resolve, I edited the script to detect additional failure scenarios..

Code: Select all

...
$FailedSessions = $TaskSessions | where {$_.status -eq "EWarning" -or $_.Status -eq "EFailed"}

if ($vm -eq $Null)
  {
    $resultFields = [Ordered]@{
        "Name" = $VMName
        "Start Time" = Get-Date
        "End Time" = Get-Date
        "Result" = "Failed"
        "Details" = "VM not found"}

    $MesssagyBody += New-Object PSObject -Prop $resultFields
  }
  elseif ($TaskSessions -eq $Null)
  {
    $resultFields = [Ordered]@{
        "Name" = $VMName
        "Start Time" = Get-Date
        "End Time" = Get-Date
        "Result" = "Failed"
        "Details" = "Task failure"}

    $MesssagyBody += New-Object PSObject -Prop $resultFields
  }
  elseif ($FailedSessions -ne $Null)
  {
...
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

VMs that literally cannot be processed (unsupported type, invalid disk type, etc.) are skipped from backup and replication jobs.

Such behaviour is not considered exceptional, thus, no excessive errors are generated. The report just takes this information from backup server without applying additional logic.

Thank you, though, for taking time to update the script and posting the modified version here; appreciated!
mkaec
Veteran
Posts: 465
Liked: 136 times
Joined: Jul 16, 2015 1:31 pm
Full Name: Marc K
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by mkaec »

Non-exceptional is one thing. But, in my case the VMs not being backed up were in the email report with a Success status as if they were. The extra logic I added actually handles some cases when the backup server cannot be queried for the status.
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

There are three task statuses: success, warning and failure. VM being skipped from processing for obvious reasons such as incompatible type or similar is not considered exceptional behaviour. Thus, neither warning nor error is generated.

Anyway, the script is provided as a courtesy, and is not supported by Veeam Technical Support. So, feel free to modify in accordance with your needs and desires.

Thanks!
mkaec
Veteran
Posts: 465
Liked: 136 times
Joined: Jul 16, 2015 1:31 pm
Full Name: Marc K
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by mkaec » 1 person likes this post

Definitely appreciated the script. It was much easier to get going with something to start off with.
daystrom
Expert
Posts: 129
Liked: 8 times
Joined: Apr 09, 2017 6:32 pm
Contact:

Script fails when multiple vms specified

Post by daystrom »

I'm creating a new ps script to backup 3 vms. However the script fails. If I use only one vm name it works?

the basics:
$VMNames = "at-dc","at-apps","tenbob"
$HostName = "at-vh"

when I step through the code I get these

Code: Select all

PS C:\Windows\system32> foreach ($VMName in $VMNames)
Missing statement body in foreach loop.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingForeachStatement
 

PS C:\Windows\system32>   $VM = Find-VBRHvEntity -Name $VMName -Server $Server
Find-VBRHvEntity : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:1 char:32
+   $VM = Find-VBRHvEntity -Name $VMName -Server $Server
+                                ~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Find-VBRHvEntity], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.FindVBRHvEntity

I can make do with three separate scripts for, one for each vm, but I'd still like to know how to get the multi vm script to work as it should. 

Full script:

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

# modified from VeeamZIP (HV).ps1
 
##################################################################
#                   User Defined Variables
##################################################################

# Names of VMs to backup separated by comma (Mandatory). For instance, $VMNames = “VM1”,”VM2”
$VMNames = "at-dc" #,"at-apps","tenbob"

# Name of vCenter or standalone host VMs to backup reside on (Mandatory)
$HostName = "at-vh"

# Directory that VM backups should go to (Mandatory; for instance, C:\Backup)
$Directory = "e:\veeam vm images"

# 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 = $False

# 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 = $False

# Email SMTP server
$SMTPServer = ""

# Email FROM
$EmailFrom = "" 

# Email TO
$EmailTo = ""

# Email subject
$EmailSubject = ""

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

$style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$style = $style + "TD{border: 1px solid black; padding: 5px; }"
$style = $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)
}
jhoughes
Veeam Vanguard
Posts: 282
Liked: 113 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Script fails when multiple vms specified

Post by jhoughes »

Delete the line return at the end of your foreach statements.

You have this:

Code: Select all

foreach ($VMName in $VMNames)
{
Change it to this instead:

Code: Select all

foreach ($VMName in $VMNames){
Husband, Father, Solutions Architect, Geek | @DenverVMUG & @DenverPSUG leader | International Speaker | Veeam Vanguard | vExpert (PRO) | Cisco Champion
daystrom
Expert
Posts: 129
Liked: 8 times
Joined: Apr 09, 2017 6:32 pm
Contact:

Re: Script fails when multiple vms specified

Post by daystrom »

Thanks that did it. The error seems to be in the original script, I just checked?
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

For me it works even with the original structure. And if it didn't work, I would have got numerous complains already (given the number of downloads). Thanks!
mkaec
Veteran
Posts: 465
Liked: 136 times
Joined: Jul 16, 2015 1:31 pm
Full Name: Marc K
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by mkaec »

Try this alternate way of specifying the VMs:

Code: Select all

$VMNames = @()
$VMNames += "at-dc"
$VMNames += "at-apps"
$VMNames += "tenbob"
Sebastian M
Lurker
Posts: 1
Liked: never
Joined: Jan 07, 2019 8:02 am
Full Name: Sebastian Niklas lasse Markussen
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Sebastian M »

can someone pls help me i have been struggling on this problem for some time and i cant figure out what the problem is? im using this script

Code: Select all

# 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 = "Win_2016_test_backup"

# Name of vCenter or standalone host VMs to backup reside on (Mandatory)
$HostName = "192.168.17.128"

# Directory that VM backups should go to (Mandatory; for instance, C:\Backup)
$Directory = "C:/backup"

# 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 = $false

# 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 = $False

# Email SMTP server
$SMTPServer = ""

# Email FROM
$EmailFrom = "" 

# Email TO
$EmailTo = ""

# Email subject
$EmailSubject = ""

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

$style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$style = $style + "TD{border: 1px solid black; padding: 5px; }"
$style = $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)
}

And im getting these errors


Code: Select all

Find-VBRHvEntity : 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 line:3 char:48
+   $VM = Find-VBRHvEntity -Name $VMName -Server $Server
+                                                ~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Find-VBRHvEntity], ParameterBindingValidationExce
   ption
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.Fi
   ndVBRHvEntity

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 line:13 char:40
+     $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compre ...
+                                        ~~~
    + CategoryInfo          : InvalidData: (:) [Start-VBRZip], ParameterBindingValidationExceptio
   n
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.St
   artVBRZip
jhoughes
Veeam Vanguard
Posts: 282
Liked: 113 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by jhoughes »

PowerShell is saying that you don't have anything in your 'Server' variable to pass into Find-VBRHvEntity.
Husband, Father, Solutions Architect, Geek | @DenverVMUG & @DenverPSUG leader | International Speaker | Veeam Vanguard | vExpert (PRO) | Cisco Champion
mkaec
Veteran
Posts: 465
Liked: 136 times
Joined: Jul 16, 2015 1:31 pm
Full Name: Marc K
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by mkaec »

And the $Server variable is populated based on the $HostName variable, which contains an IP address. I wonder if IP addresses are not supported and an actual host name is required.
jhoughes
Veeam Vanguard
Posts: 282
Liked: 113 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by jhoughes »

You need to get the server object itself first, as it is registered with Veeam. It's not a direct query against a host, so it needs to match the server name that you used to connect it within Veeam.

This is the cmdlet that is being run to populate the Server variable, you could run it first with no parameters to return all valid results to determine which you are targeting as the value for the -Server parameter:
https://helpcenter.veeam.com/docs/backu ... tml?ver=95
Husband, Father, Solutions Architect, Geek | @DenverVMUG & @DenverPSUG leader | International Speaker | Veeam Vanguard | vExpert (PRO) | Cisco Champion
maksim_andreev
Lurker
Posts: 2
Liked: never
Joined: Feb 27, 2019 6:37 am
Full Name: Maksim Andreev
Contact:

[MERGED] Exclude several virtual disks from processing

Post by maksim_andreev »

Good afternoon dear experts!
Help change all known script from a respected human on this forum https://www.veeam.com/blog/ru/veeam-bac ... shell.html Author: Vladimir Eremin. Most recently updated to the new version of veeam backup & replication 9.5 update 4 in which it is possible to make a backup VM selective disks (exclude disks from the backup VM) Found several articles on this forum on this topic ( powershell-f26/new-veean-backup-job-script-t48735.html ) but it is not clear how to combine in one script

Help me please I'd appreciate it.
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

You cannot exclude certain disks from VeeamZIP backup. Thanks!
mkaec
Veteran
Posts: 465
Liked: 136 times
Joined: Jul 16, 2015 1:31 pm
Full Name: Marc K
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by mkaec »

Maksim,

Your best bet might to be remove the select VMs from the script and try creating a separate backup job through the GUI for them.
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Should work fine. Just so you know starting from Update 4 instead of Free Edition we provide Community Edition with 10 Standard instances included, which means you can protect up to 10 VMs via backup or replication jobs and continue protecting any number VMs via VeeamZIP. Thanks!
maksim_andreev
Lurker
Posts: 2
Liked: never
Joined: Feb 27, 2019 6:37 am
Full Name: Maksim Andreev
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by maksim_andreev »

Thanks you! If the script can not be changed, then we will create the task through the graphic interface veeam backup & replication 9.5 update 4.
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

It's not about the script being unchangeable, but more about VeeamZIP functionality not being able to exclude certain disks from processing.

To achieve that you should create backup jobs either manually or automatically via PowerShell.

Thanks!
mkaec
Veteran
Posts: 465
Liked: 136 times
Joined: Jul 16, 2015 1:31 pm
Full Name: Marc K
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by mkaec » 2 people like this post

Before 9.5U4, the answer to the question would have been simple -- "Can't do it."

Now you can thanks to 9.5U4 including limited free full functionality. But the PowerShell script is based on the older free functionality that cannot exclude disks.
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests