PowerShell script exchange
Post Reply
skelly
Lurker
Posts: 2
Liked: never
Joined: Mar 07, 2018 6:00 am
Full Name: Sean Kelly
Contact:

[MERGED] can't get-vbrcredentials in script

Post by skelly »

Using the script from https://forums.veeam.com/post250811.htm ... ls#p250811 but adding the following to try to backup to a network share

Code: Select all

$NetCreds = Get-VBRCredentials -Name "admin"
and

Code: Select all

$ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention -EncryptionKey $EncryptionKey -NetworkCredentials $NetCreds
to backup up to a network share results in a failure:

Code: Select all

Start-VBRZip : Cannot convert 'System.Object[]' to the type 'Veeam.Backup.Common.CCredentials' required by parameter 'NetworkCredentials'. Specified method 
is not supported.
At C:\scripts\VeeamZIP.ps1:92 char:174
+ ... nableQuiescence) -AutoDelete $Retention -NetworkCredentials $NetCreds
+ ~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Start-VBRZip], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Veeam.Backup.PowerShell.Cmdlets.StartVBRZip
Further, if I type in powershell

Code: Select all

Get-VBRCredentials -Name "admin" 
I get two lots of credentials for "admin" when the GUI only shows one "admin" in the credentials manager:

Code: Select all

PS C:\scripts> Get-VBRCredentials -Name "admin"


Id : 3c88fc47-5bc6-4757-9127-61e5ac97331d
IsLocalProtect : True
Name : admin
CurrentUser : False
UserName : admin
UserNameOnly : admin
DomainName : .
EncryptedPassword : 
Description : admin
ChangeTimeLocal : 1/11/2017 1:14:49 PM
ChangeTimeUtc : 1/11/2017 3:14:49 AM
IsEmpty : False
PasswordIsNull : True

Id : 22991cc8-f227-440c-8191-d90fc178d9f5
IsLocalProtect : True
Name : admin
CurrentUser : False
UserName : admin
UserNameOnly : admin
DomainName : .
EncryptedPassword : 
Description : NAS admin
ChangeTimeLocal : 30/10/2017 9:59:20 AM
ChangeTimeUtc : 29/10/2017 11:59:20 PM
IsEmpty : False
PasswordIsNull : True
What am I doing wrong? Pretty sure it's a Get-VBRCredentials issue and not a UNC or mapped drive issue (I've tried both, and can read/write to both through explorer and use the Veeam GUI to do VeeamZIP backups to there...)

It works beautifully when backing up to local storage, but then that doesn't need credentials.

Sean
veremin
Product Manager
Posts: 20270
Liked: 2252 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 seems that duplicated credential entities exist in product database for some reason. As the results, both credentials get returned by Get-VBRCredentials script.

You have to either filter out additional credentials or clean up the database from obsolete entity (might be worth contacting support team, if you take this path).

Thanks.
skelly
Lurker
Posts: 2
Liked: never
Joined: Mar 07, 2018 6:00 am
Full Name: Sean Kelly
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by skelly »

Yay! It is indeed duplicate/obsolete entries in the database. I have two NAS and the username is the same for both so Get-VBRcredentials cannot distinguish based on the username. Maybe I should use some other method? Renaming the second NAS's entry fixed it but I still need to have a way to get the right VBRcredentials when two devices use the same username (potentially different passwords).

Next thought is, with the script, how can I get the actual warning rather than just the email saying the job finished with a warning?
franklammers
Lurker
Posts: 1
Liked: never
Joined: Mar 14, 2018 8:27 am
Full Name: frank lammers
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by franklammers »

hello i try the script and i have this :

Code: Select all

Asnp : No snap-ins have been registered for Windows PowerShell version 4.
At line:1 char:1
+ Asnp VeeamPSSnapin
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (VeeamPSSnapin:String) [Add-PSSnapin], PSArgumentException
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
 
Get-VBRServer : 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 line:3 char:11
+ $Server = Get-VBRServer -name $HostName
+           ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-VBRServer:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
Find-VBRHvEntity : The term 'Find-VBRHvEntity' 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 line:8 char:9
+   $VM = Find-VBRHvEntity -Name $VMName -Server $Server
+         ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Find-VBRHvEntity:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
Get-Content : Cannot bind argument to parameter 'Path' because it is an empty string.
At line:12 char:58
+     $EncryptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | Conver ...
+                                                          ~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Get-Content], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.GetContentCommand
 
Start-VBRZip : 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 line:13 char:19
+     $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $Comp ...
+                   ~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Start-VBRZip:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

hello i try the script and i have this :
Try the workarounds mentioned here.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Maybe I should use some other method?
Nope, you should try to find distinguishing factor and filter unnecessary credentials, based on it.
Next thought is, with the script, how can I get the actual warning rather than just the email saying the job finished with a warning?
As far as I remember, HTML report does contain warning message.
Calippo_81
Novice
Posts: 5
Liked: never
Joined: Mar 26, 2018 9:16 am
Contact:

[MERGED] Powershell backup-script is not starting

Post by Calippo_81 »

Hi!

Have follow this guide by Vladimir: https://www.veeam.com/blog/veeam-backup ... shell.html

But when I try to run the script with PS nothingg is happen, script won`t start.

Here is the PS-code:

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

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

# Directory that VM backups should go to (Mandatory; for instance, C:\Backup)
$Directory = "\\Deploy-pc\servername-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 = $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 = "In1Month"
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Try to open PowerShell (backup server -> menu -> console -> powershell), run the lines one by one and check whether everything works as expected: variables get assigned properly, values get returned properly, there are no permission problem, etc. Thanks.
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 »

Powershell is no problem to open. Have done that, no errors at all. I run the script with no errors, but no backup is starting.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Try to run the simplified version of the script in PS ISE (line by line) and see which line fails:

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
Thanks.
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 »

Thx!

Some errors.

Code: Select all

PS C:\Users\Administrator.BS\Desktop> $Server = Get-VBRServer -name $HostName
Get-VBRServer : 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, ver
ify that the path is correct and try again.
At line:1 char:11
+ $Server = Get-VBRServer -name $HostName
+           ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-VBRServer:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Users\Administrator.BS\Desktop> $VM = Find-VBRViEntity -Name $VMName -Server $Server
Find-VBRViEntity : 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 include
d, verify that the path is correct and try again.
At line:1 char:7
+ $VM = Find-VBRViEntity -Name $VMName -Server $Server
+       ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Find-VBRViEntity:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Start-VBRZip : 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, verif
y that the path is correct and try again.
At line:1 char:1
+ Start-VBRZip -Entity $VM -Folder $Directory
+ ~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Start-VBRZip:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Either the PS snap-in is not installed on the computer or it does get added in the beginning of the script (asnp VeeamPSSnapin). Thanks.
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 »

Hi!

This script works when I run it from Powershell-console from Veeam, but not my regular PS. Why ? VeeamPSSnapin is installed, I have checked that with command: get-PSSnapIn -Registered

Code: Select all

$VMName = "VM1"
$HostName = "BSHYP01"
$Directory = "\\Deploy-pc\bshyp01-backup"
$Server = Get-VBRServer -name $HostName
$Server
$VM = Find-VBRHvEntity -Name $VMName -Server $Server
$VM
Start-VBRZip -Entity $VM -Folder $Directory
veremin
Product Manager
Posts: 20270
Liked: 2252 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 script gets executed under different accounts with different sets of permissions. Try to run it under Administrator account and see whether it helps. Thanks.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Have you added the mentioned line in the beginning of the script?

Code: Select all

Asnp VeeamPSSnapin
Thanks.
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 »

Asnp VeeamPSSnapin did the trick! Thx man, now it`s working =)
veremin
Product Manager
Posts: 20270
Liked: 2252 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.

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 »

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.
veremin
Product Manager
Posts: 20270
Liked: 2252 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 veremin »

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 »

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)
}
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

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 »

That script worked correctly, I can return all VMs from the cluster regardless of node.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin » 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 »

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 »

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
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

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 »

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
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

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 »

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 »

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 16 guests