PowerShell script exchange
Calippo_81
Novice
Posts: 5
Liked: never
Joined: Mar 26, 2018 9:16 am
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Calippo_81 » Mar 27, 2018 12:49 pm

Asnp VeeamPSSnapin did the trick! Thx man, now it`s working =)

v.Eremin
Veeam Software
Posts: 15142
Liked: 1141 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by v.Eremin » Mar 27, 2018 12:51 pm

You're welcome.

To work with VB&R PS cmdlets and objects you need to call the snap-in within your script. Add-PSSSnapin (or asnp) does exactly that.

Thanks.

edmacfly
Novice
Posts: 4
Liked: never
Joined: Apr 04, 2018 9:26 am
Full Name: Edward Smith
Contact:

[MERGED] Hyper-V Cluster backup only backing up one node

Post by edmacfly » Apr 04, 2018 9:57 am

I am running the latest free edition of Veeam on a standalone Windows Server box. I'm attempting to use Powershell on this machine to trigger a backup of all five guest VMs on a two node Window Server 2012 R2 Hyper-V cluster. Everything appeared to have worked fine but it now seems that the VeeamZIP backup is only backing up VMs from one of the nodes. I've attempted adding the nodes as separate machines and backing them up independently but that didn't go well. Has anyone had a similar experience to me and if so, can anyone offer me some advice to remedy this issue? Thanks in advance.

v.Eremin
Veeam Software
Posts: 15142
Liked: 1141 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Hyper-V Cluster backup only backing up one node

Post by v.Eremin » Apr 04, 2018 10:26 am

How cluster is added to a backup console? As a cluster or two nodes are added independently? Also, how you script looks like, especially part that calls Get-VBRServer cmdlet - aren't you passing there just a single node, instead of cluster? Thanks.

edmacfly
Novice
Posts: 4
Liked: never
Joined: Apr 04, 2018 9:26 am
Full Name: Edward Smith
Contact:

Re: Hyper-V Cluster backup only backing up one node

Post by edmacfly » Apr 04, 2018 10:55 am

Thanks for the reply.

I added the cluster as a cluster within backup console. I did try adding each node separately to see if that helped but it did not work, so now I only have the cluster added as a cluster.

In terms of the script, I'm using the script you posted (thank you).

Code: Select all

# Author: Vladimir Eremin
# Created Date: 3/24/2015
# http://forums.veeam.com/member31097.html
# Modified to support multiple Hyper-V hosts. Automatically enumerate VM's and back them all up
# 12/19/2015 by Snarfattack
 
##################################################################
#                   User Defined Variables
##################################################################
 
#You must install the Hyper-V Management Tools, including the Powershell Cmdlets
#Names of VMHosts to backup VMs on (Mandatory)
$VMHosts = "HYPERVCLUSTER"
 
#Names of VMs to Skip (Optional)
$VMSkipNames = ""
 
# Directory that VM backups should go to (Mandatory; for instance, C:\Backup)
$Directory = "D:\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 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 = "TomorrowNight"
 
##################################################################
# Notification Settings
##################################################################
 
# Enable notification (Optional)
$EnableNotification = $True
 
# Email SMTP server
$SMTPServer = "Exchange"
 
# Email FROM
$EmailFrom = "backup@mydomain.com"
 
# Email TO
$EmailTo = "ed@mydomain.com"
 
# Email subject
$EmailSubject = "Veeam Backup Report"
 
##################################################################
#                   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
 
 
$MesssagyBody = @()
 
foreach ($VMHost in $VMHosts)
{
    $Server = Get-VBRServer -name $VMHost
 
    $VMNames = Get-VM -ComputerName $VMHost | Where-Object {$_.State –eq 'Running'} | Select Name
    foreach ($VMName in $VMNames)
    {
      if ($VMSkipNames -notcontains $VMName.Name)
      {
          $VM = Find-VBRHvEntity -Name $VMName.Name -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)
}

v.Eremin
Veeam Software
Posts: 15142
Liked: 1141 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by v.Eremin » Apr 04, 2018 11:51 am

Can you try the simplified version of the script to see whether a VM from the second node gets returned properly?

Code: Select all

Asnp VeeamPSSnapin
$VMName = "Name of a VM that resides on the second node"
$HostName = "Name of HV Cluster"
$Server = Get-VBRServer -name $HostName
$Server
$VM = Find-VBRHvEntity -Name $VMName -Server $Server
$VM
Thanks.

edmacfly
Novice
Posts: 4
Liked: never
Joined: Apr 04, 2018 9:26 am
Full Name: Edward Smith
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by edmacfly » Apr 04, 2018 1:42 pm

That script worked correctly, I can return all VMs from the cluster regardless of node.

v.Eremin
Veeam Software
Posts: 15142
Liked: 1141 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by v.Eremin » Apr 04, 2018 3:12 pm 1 person likes this post

Then, something must be wrong with the way you get VMs or their name in your original script. Can you try to get them a bit differently and see whether it helps:

Code: Select all

$VMs = Find-VBRHvEntity -Server $Server | where {$_.type -eq "VM"}
foreach ($VM in $VMs)


Thanks.

edmacfly
Novice
Posts: 4
Liked: never
Joined: Apr 04, 2018 9:26 am
Full Name: Edward Smith
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by edmacfly » Apr 04, 2018 4:03 pm

That has sorted it! Thanks so much for taking the time to respond and remedy the issue :)

Ozy
Lurker
Posts: 1
Liked: never
Joined: Apr 04, 2018 6:54 pm
Full Name: Chris Johnson
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Ozy » Apr 04, 2018 7:07 pm

I'm using the script provided on the web page for starting Powershell scheduled backups. I'm kind of in a pickle. I need to run the script as my domain account so the CIFS share has the proper credentials, but I'm getting these errors:

Code: Select all

PS C:\> .\VeeamZIP.ps1
Get-VBRServer : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Veeam\Veeam Backup and Replication' is denied.
At C:\VeeamZIP.ps1:71 char:11
+ $Server = Get-VBRServer -name $HostName
+           ~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException

Find-VBRViEntity : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Veeam\Veeam Backup and Replication' is
denied.
At C:\VeeamZIP.ps1:76 char:9
+   $VM = Find-VBRViEntity -Name $VMName -Server $Server
+         ~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException

Start-VBRZip : Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\Veeam\Veeam Backup and Replication' is denied.
At C:\VeeamZIP.ps1:86 char:19
+     $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $Comp ...
+                   ~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException

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
I've tried granting Full Control on the parent key and sub-keys without any success to Domain Admins, Everyone, nothing works. If I run as an administrator, it works but fails to write to my CIFS share due to credentials.

Code: Select all

Processing finished with errors at 4/4/2018 11:10:56 AM Error: Access is denied. Failed to process [isFileExists].
Is there any way I can pass credentials to the CIFS mount in the script and continue to run it as administrator, or perhaps something I'm overlooking to overcome the RegKey denial?

Thanks so much

v.Eremin
Veeam Software
Posts: 15142
Liked: 1141 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by v.Eremin » Apr 05, 2018 1:06 pm

CIFS credentials can be passed via -NetworkCredentials parameter.

As to the error you get, try to search this subforum - it's been discussed several times already.

Thanks.

exploit
Lurker
Posts: 1
Liked: never
Joined: Apr 26, 2018 8:23 am
Full Name: Sergey
Contact:

[MERGED] Problem with backups from script

Post by exploit » Apr 26, 2018 8:56 am

Hello. Sorry of my english.
I use VBR Free 9.5.
I have ESXi Server.
I have a script to backup my Virtual machines.

Code: Select all

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

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

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

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

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

# Email SMTP server
$SMTPServer = "smtp.company.com"

# Email FROM
$EmailFrom = "sysadmin@company.com" 

# Email TO
$EmailTo = "sysadmin@company.com"

# Email subject
$EmailSubject = "veeam ok"

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

I connected a network share from NAS to my PC (Drive V:\)
NAS has been integrated to Active Directory
This script not work with this Drive (no errors and no actions - it just compute VM size and finish)
But it work with any local Drive.
Moreover,if I start VeeamZIP to Drive V:\ directly from VBR,then it work, backup process work correct.
Script work from my AD admin account
Help me please, give me advice, why VeeamZIP to V:\ Drive is not working from script

v.Eremin
Veeam Software
Posts: 15142
Liked: 1141 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by v.Eremin » Apr 27, 2018 10:48 am

Can you try to specify -NetworkCredentials parameter in Start-VBRZip cmdlet and see whether it solves the issue? NetworkCredentials is the credentials you want to use for authenticating with the shared folder. Thanks.

Coverdale
Lurker
Posts: 2
Liked: never
Joined: May 16, 2018 12:11 pm
Full Name: Charlie Coverdale
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Coverdale » May 16, 2018 1:15 pm

Hi all,

We have recently had to install VEEAM on a new server and what was working perfectly is now just NOT (We are now using Update3... not sure if the script needs changing... added below).

This is to back up VMs on a Win 2012 R2 Cluster Hyper-V environment

We get this error:

Code: Select all

Start-VBRZip : Cannot bind parameter 'Entity'. Cannot convert the "" value of type "System.String" to type "Veeam.Backup.Common.IItem".
At C:\directory\VeeamZIP.ps1:86 char:40
+     $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compre ...
+                                        ~~~
    + CategoryInfo          : InvalidArgument: (:) [Start-VBRZip], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Veeam.Backup.PowerShell.Cmdlets.StartVBRZip
 
You cannot call a method on a null-valued expression.
At C:\directory\VeeamZIP.ps1:91 char:5
+     $TaskSessions = $ZIPSession.GetTaskSessions().logger.getlog().upd ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Coverdale
Lurker
Posts: 2
Liked: never
Joined: May 16, 2018 12:11 pm
Full Name: Charlie Coverdale
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Coverdale » May 16, 2018 3:11 pm

OK I figured it out ... We are running Hyper-V and not VMWare so all I needed to do was change Find-VBRViEntity -Name $VMName -Server $Server to Find-VBRHvEntity -Server $server -Name $VMs

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests