Problem with PowerShell script/Veeam

PowerShell script exchange

Problem with PowerShell script/Veeam

Veeam Logoby KGray2k16 » Tue Mar 15, 2016 10:00 am

Hi All,

Am trying to use the PowerShell script for automating backups. Having some issues when adding more than one VM to backup, see below:

Code: Select all
# Names of VMs to backup separated by semicolon (Mandatory)
$VMNames = "LTBCC2L,LTBCC2L2"

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

# Directory that VM backups should go to (Mandatory; for instance, C:\Backup)
$Directory = "D:\Backups\Veeam Backups\Test"

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


Works fine for just one of the listed VM's independently, only when I try to backup 2 as per the config I get the following:

Code: Select all
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 D:\Veeam\Electra.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


Can any help me with this please?

Kind regards.
KGray2k16
Influencer
 
Posts: 10
Liked: 1 time
Joined: Tue Mar 15, 2016 9:45 am
Full Name: Kristian Gray

Re: Problem with PowerShell script/Veeam

Veeam Logoby PTide » Tue Mar 15, 2016 10:09 am

Hi,

Please check the variables that you are passing to a cmdlet - I can't see a $VM variable anywhere in your code, only $VMNames.

Thank you.
PTide
Veeam Software
 
Posts: 3022
Liked: 247 times
Joined: Tue May 19, 2015 1:46 pm

Re: Problem with PowerShell script/Veeam

Veeam Logoby KGray2k16 » Tue Mar 15, 2016 10:13 am

This is the rest of the script in its entirety, not sure if this covers your questions. (PowerShell novice here)

Code: Select all
##################################################################
#                   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-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)
}
KGray2k16
Influencer
 
Posts: 10
Liked: 1 time
Joined: Tue Mar 15, 2016 9:45 am
Full Name: Kristian Gray

Re: Problem with PowerShell script/Veeam

Veeam Logoby KGray2k16 » Tue Mar 15, 2016 10:17 am

Just to add that I downloaded the script from Veeam and didn't create it myself. It was created by Vladimir Eremin.

Thanks.
KGray2k16
Influencer
 
Posts: 10
Liked: 1 time
Joined: Tue Mar 15, 2016 9:45 am
Full Name: Kristian Gray

Re: Problem with PowerShell script/Veeam

Veeam Logoby vmniels » Tue Mar 15, 2016 10:22 am

Can you try using:
Code: Select all
$VMNames = "LTBCC2L;LTBCC2L2"


Replace the , by ;
VCP-DCV
Veeam Certified Engineer
http://foonet.be
vmniels
Veeam Software
 
Posts: 1517
Liked: 328 times
Joined: Mon Jul 15, 2013 11:09 am
Full Name: Niels Engelen

Re: Problem with PowerShell script/Veeam

Veeam Logoby KGray2k16 » Tue Mar 15, 2016 10:44 am

Apologies, I had already a ";" which produces the same error, I only used "," as an attempt to make it work.
KGray2k16
Influencer
 
Posts: 10
Liked: 1 time
Joined: Tue Mar 15, 2016 9:45 am
Full Name: Kristian Gray

Re: Problem with PowerShell script/Veeam

Veeam Logoby PTide » Tue Mar 15, 2016 10:55 am

Are you trying to backup Hyper-V VMs or VMware?

If the latter then please make sure that this string:

Code: Select all
Find-VBRViEntity -Name $VMName -Server $Server


returns value which is not null.

If you are trying to backup Hyper-V VMs then you need to download another script.
PTide
Veeam Software
 
Posts: 3022
Liked: 247 times
Joined: Tue May 19, 2015 1:46 pm

Re: Problem with PowerShell script/Veeam

Veeam Logoby KGray2k16 » Tue Mar 15, 2016 11:05 am

It is a VMWare host that I am trying to backup.

As I mentioned it works without issue when I only specify one VM to backup as soon as I add another or more it fails.

How can I check what is returned by running the above string, "Find-VBRViEntity -Name $VMName -Server $Server"

I entered it into PowerShell but nothing happened.

Cheers.
KGray2k16
Influencer
 
Posts: 10
Liked: 1 time
Joined: Tue Mar 15, 2016 9:45 am
Full Name: Kristian Gray

Re: Problem with PowerShell script/Veeam

Veeam Logoby PTide » Tue Mar 15, 2016 11:09 am

Enter this:

Code: Select all
$VMNames = "LTBCC2L;LTBCC2L2"

$HostName = "Server1"

foreach ($VMName in $VMNames)
{
  $VM = Find-VBRViEntity -Name $VMName -Server $Server
 echo $VM
}
PTide
Veeam Software
 
Posts: 3022
Liked: 247 times
Joined: Tue May 19, 2015 1:46 pm

Re: Problem with PowerShell script/Veeam

Veeam Logoby KGray2k16 » Tue Mar 15, 2016 11:19 am

I have been running this in Windows PowerShell ISE, is this correct? Nothing displays after running the above.
KGray2k16
Influencer
 
Posts: 10
Liked: 1 time
Joined: Tue Mar 15, 2016 9:45 am
Full Name: Kristian Gray

Re: Problem with PowerShell script/Veeam

Veeam Logoby vmniels » Tue Mar 15, 2016 11:41 am

Can you try Write-Ouput $VM instead of echo $VM ?

It should output 2 things
VCP-DCV
Veeam Certified Engineer
http://foonet.be
vmniels
Veeam Software
 
Posts: 1517
Liked: 328 times
Joined: Mon Jul 15, 2013 11:09 am
Full Name: Niels Engelen

Re: Problem with PowerShell script/Veeam

Veeam Logoby KGray2k16 » Tue Mar 15, 2016 12:16 pm

This is what I get, (I should add the Hostname is actually "RDVirtual1"

Code: Select all
ConnHostId : 76aa9244-10de-4427-9531-b013935f6e79
ConnHost   : Veeam.Backup.Core.Common.CHost
Type       : Esx
Reference  : ha-host
Id         : 76aa9244-10de-4427-9531-b013935f6e79_ha-host
Name       : RDVirtual1
Path       : RDVirtual1
KGray2k16
Influencer
 
Posts: 10
Liked: 1 time
Joined: Tue Mar 15, 2016 9:45 am
Full Name: Kristian Gray

Re: Problem with PowerShell script/Veeam

Veeam Logoby vmniels » Tue Mar 15, 2016 12:18 pm

Can you try the script again but with 2 different lines:

First with: $VMNames = "LTBCC2L"
Second with: $VMNames = "LTBCC2L2"

Do they both give output?
VCP-DCV
Veeam Certified Engineer
http://foonet.be
vmniels
Veeam Software
 
Posts: 1517
Liked: 328 times
Joined: Mon Jul 15, 2013 11:09 am
Full Name: Niels Engelen

Re: Problem with PowerShell script/Veeam

Veeam Logoby KGray2k16 » Tue Mar 15, 2016 12:24 pm

Okay so I entered this

Code: Select all
$VMNames = "LTBCC2L"
$VMNames = "LTBCC2L2"

$HostName = "RDVirtual1"

foreach ($VMNames in $HostName)
{
  $VM = Find-VBRViEntity -Name $VMName -Server $Server
 Write-Output $VM
}


And I still only had one output, see below

Code: Select all
ConnHostId : 76aa9244-10de-4427-9531-b013935f6e79
ConnHost   : Veeam.Backup.Core.Common.CHost
Type       : Esx
Reference  : ha-host
Id         : 76aa9244-10de-4427-9531-b013935f6e79_ha-host
Name       : RDVirtual1
Path       : RDVirtual1
KGray2k16
Influencer
 
Posts: 10
Liked: 1 time
Joined: Tue Mar 15, 2016 9:45 am
Full Name: Kristian Gray

Re: Problem with PowerShell script/Veeam

Veeam Logoby vmniels » Tue Mar 15, 2016 12:25 pm

Yes but this won't work. Basically you overwrite your value. Can you try with just $VMNames = "LTBCC2L" ?

Somehow if you use 2 it fails so we need to troubleshoot if both VM's work fine first
VCP-DCV
Veeam Certified Engineer
http://foonet.be
vmniels
Veeam Software
 
Posts: 1517
Liked: 328 times
Joined: Mon Jul 15, 2013 11:09 am
Full Name: Niels Engelen

Next

Return to PowerShell



Who is online

Users browsing this forum: Yahoo [Bot] and 8 guests