PowerShell script exchange
Post Reply
cormack12
Novice
Posts: 4
Liked: never
Joined: Aug 11, 2015 7:41 am
Full Name: peter cormack
Contact:

Powershell script failing for scripted backups?

Post by cormack12 »

Hi,

I am using the script from here to try and script multiple backups. I am attempting to use the script detailed by Veeam here:

http://www.veeam.com/blog/veeam-backup- ... shell.html

I had a nightmare getting the powershell script in there first but now got it working.However, running the script gives an error here:

Code: Select all

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\DailyBackups.ps1:76 char:48
+   $VM = Find-VBRViEntity -Name $VMName -Server $Server
The relevant parts of the code I have populated are (if you can't see the value, default in the script is used):

Code: Select all

# Names of VMs to backup separated by comma (Mandatory). For instance, $VMNames = “VM1”,”VM2”
$VMNames = "vm01"
 
# Name of vCenter or standalone host VMs to backup reside on (Mandatory)
$HostName = "cluster-hyperv"
 
# Directory that VM backups should go to (Mandatory; for instance, C:\Backup)
$Directory = "C:\Backups"

# Protect resulting backup with encryption key (Optional; $True/$False)
$EnableEncryption = $False

# Enable notification (Optional)
$EnableNotification = $False
Any ideas?
PTide
Product Manager
Posts: 6408
Liked: 724 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Powershell script failing for scripted backups?

Post by PTide »

Hi, and welcome to the community.

Have you cpecified the $Hostname variable here?

Code: Select all

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

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

# Name of vCenter or standalone host VMs to backup reside on (Mandatory)
$HostName = ""
Thank you.
cormack12
Novice
Posts: 4
Liked: never
Joined: Aug 11, 2015 7:41 am
Full Name: peter cormack
Contact:

Re: Powershell script failing for scripted backups?

Post by cormack12 »

Hi,

Thanks for the welcome! Yes, I have specified the variable as:

physical hyperV host
hyperV cluster name
server where VBR is installed

All to no avail, same issue persists. Same error. Strange.
PTide
Product Manager
Posts: 6408
Liked: 724 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Powershell script failing for scripted backups?

Post by PTide »

Could you check if the server you've specified is available?
You may have noticed, that the $Hostname variable is passed to

$Server = Get-VBRServer -name $HostName and $Server is passed to

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

If $Server is null then the output of Get-VBRServer is null for some reason.

Get-VBRserver returns hosts connected to Veeam Backup & Replication, which means that your $HostName is not connected or you have a typo in $HostName

Please try executing Get-VBRServer and check if $HostName is in the list.

Thank you.
cormack12
Novice
Posts: 4
Liked: never
Joined: Aug 11, 2015 7:41 am
Full Name: peter cormack
Contact:

Re: Powershell script failing for scripted backups?

Post by cormack12 »

Hi,

I opened the entire script in ISE and had a thorough look at it this morning. OK, so I've for the time being just used one value to avoid confusion. So I've entered my variables into the powershell script, the pertinent ones being the $VMname and $VMHost

The script fails with the following message:

Code: Select all

PS C:\Windows\System32\WindowsPowerShell\v1.0> C:\scripts\DailyBackups.ps1
Find-VBRViEntity : Unable to cast object of type 'Veeam.Backup.Core.Infrastructure.CScvmmItem' to type 
'Veeam.Backup.Core.Infrastructure.IViItem'.
At C:\scripts\DailyBackups.ps1:76 char:9
+   $VM = Find-VBRViEntity -Name $VMName -Server $Server
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Find-VBRViEntity], InvalidCastException
    + FullyQualifiedErrorId : System.InvalidCastException,Veeam.Backup.PowerShell.Command.FindVBRViEntity
 
Start-VBRZip : Cannot validate argument on parameter 'Entity'. The argument is null. Provide a valid value for the argument, and 
then try running the command again.
At C:\scripts\DailyBackups.ps1:86 char:40
+     $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $Comp ...
+                                        ~~~
    + CategoryInfo          : InvalidData: (:) [Start-VBRZip], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Commands.Backup.StartVBRZip
I get the following info when echoing the values stored in the variables:

Code: Select all

PS C:\Windows\System32\WindowsPowerShell\v1.0> echo $server

Info               : KLAL-SVR-VMM01 (Microsoft Virtual Machine Manager Server)
ParentId           : 00000000-0000-0000-0000-000000000000
Id                 : 539fd7ff-0d83-44af-b4bf-70433fd789bd
Name               : KLAL-SVR-VMM01
RealName           : KLAL-SVR-VMM01
Reference          : 
Description        : Created by KLAL\administrator at 10/08/2015 14:19:31.
IsUnavailable      : False
Type               : Scvmm
ApiVersion         : Unknown
PhysHostId         : 00000000-0000-0000-0000-000000000000
ProxyServicesCreds : Veeam.Backup.Common.CCredentials

PS C:\Windows\System32\WindowsPowerShell\v1.0> echo $hostname
KLAL-SVR-VMM01

PS C:\Windows\System32\WindowsPowerShell\v1.0> echo $VMName
Running the problematic line now gives me

Code: Select all

PS C:\Windows\System32\WindowsPowerShell\v1.0> Find-VBRViEntity -Name $VMName -Server $Server
Find-VBRViEntity : Unable to cast object of type 'Veeam.Backup.Core.Infrastructure.CScvmmItem' to type 
'Veeam.Backup.Core.Infrastructure.IViItem'.
At line:1 char:1
+ Find-VBRViEntity -Name $VMName -Server $Server
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Find-VBRViEntity], InvalidCastException
    + FullyQualifiedErrorId : System.InvalidCastException,Veeam.Backup.PowerShell.Command.FindVBRViEntity
I've also included the output of Get-VBRServer for4 completeness:

Code: Select all

PS C:\Windows\System32\WindowsPowerShell\v1.0> Get-VBRServer

Info               : KLAL-SVR-HV01.KLAL.GSFA.UK (Microsoft Hyper-V Server)
ParentId           : 1f608259-0a1d-475e-88d5-e550067fb548
Id                 : 12c9640e-c45e-4ea6-8007-459d6b621077
Name               : KLAL-SVR-HV01.KLAL.GSFA.UK
RealName           : KLAL-SVR-HV01.KLAL.GSFA.UK
Reference          : b9d5c45f-9ab9-49a8-a627-a53b6cc523d0
Description        : 
IsUnavailable      : False
Type               : HvServer
ApiVersion         : Unknown
PhysHostId         : ecce2075-ee35-44d9-9be7-e334b58e60b2
ProxyServicesCreds : Veeam.Backup.Common.CCredentials

Info               : KLAL-SVR-VMM01 (Microsoft Virtual Machine Manager Server)
ParentId           : 00000000-0000-0000-0000-000000000000
Id                 : 539fd7ff-0d83-44af-b4bf-70433fd789bd
Name               : KLAL-SVR-VMM01
RealName           : KLAL-SVR-VMM01
Reference          : 
Description        : Created by KLAL\administrator at 10/08/2015 14:19:31.
IsUnavailable      : False
Type               : Scvmm
ApiVersion         : Unknown
PhysHostId         : 00000000-0000-0000-0000-000000000000
ProxyServicesCreds : Veeam.Backup.Common.CCredentials

Info               : This server (Microsoft Windows Server)
ParentId           : 00000000-0000-0000-0000-000000000000
Id                 : 6745a759-2205-4cd2-b172-8ec8f7e60ef8
Name               : This server
RealName           : KLAL-SVR-DPM01
Reference          : 
Description        : 
IsUnavailable      : False
Type               : Local
ApiVersion         : Unknown
PhysHostId         : d7c4ff97-b99b-4d1f-884d-283b7b6b9ee3
ProxyServicesCreds : 

Info               : KLAL-SVR-HV02.KLAL.GSFA.UK (Microsoft Hyper-V Server)
ParentId           : 1f608259-0a1d-475e-88d5-e550067fb548
Id                 : 182946f6-1e8f-4cb9-bc7e-aa8b5b58d7b5
Name               : KLAL-SVR-HV02.KLAL.GSFA.UK
RealName           : KLAL-SVR-HV02.KLAL.GSFA.UK
Reference          : d9fd8704-6dc4-4bf5-99f1-00fbe1bfa8af
Description        : 
IsUnavailable      : False
Type               : HvServer
ApiVersion         : Unknown
PhysHostId         : a166f94e-3c64-43e0-8928-9ac25f50fcc2
ProxyServicesCreds : Veeam.Backup.Common.CCredentials

Info               : KLAL-CLUS-HYPERV.KLAL.GSFA.UK (Microsoft Hyper-V Cluster)
ParentId           : 539fd7ff-0d83-44af-b4bf-70433fd789bd
Id                 : 1f608259-0a1d-475e-88d5-e550067fb548
Name               : KLAL-CLUS-HYPERV.KLAL.GSFA.UK
RealName           : KLAL-CLUS-HYPERV.KLAL.GSFA.UK
Reference          : da994770-8994-4964-965f-b5b792b0e456
Description        : 
IsUnavailable      : False
Type               : HvCluster
ApiVersion         : Unknown
PhysHostId         : 00000000-0000-0000-0000-000000000000
ProxyServicesCreds : Veeam.Backup.Common.CCredentials

Full script viewable here:

http://pastebin.com/SvQgfWeg
PTide
Product Manager
Posts: 6408
Liked: 724 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Powershell script failing for scripted backups?

Post by PTide »

Hi,

This:
$VM = Find-VBRViEntity -Name $VMName -Server $Server
Is for VMware

and this:
$VM = Find-VBRHvEntity -Name $VMName -Server $Server
is for Hyper-V, which, I believe, is what you use:
KLAL-SVR-HV01.KLAL.GSFA.UK (Microsoft Hyper-V Server)
Please replace the vmware cmdlet with hyper-v one and try again.

P.S. Sorry for misleading - I could have noticed that you were trying to use vmware cmdlet in a hyper-v environment in your 1st post.

Thank you.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell script failing for scripted backups?

Post by veremin »

There must be two versions of the script provided in the blog post. One for VMware deployments, another for Hyper-V ones. So, make sure that the right version is used. Thanks.
cormack12
Novice
Posts: 4
Liked: never
Joined: Aug 11, 2015 7:41 am
Full Name: peter cormack
Contact:

Re: Powershell script failing for scripted backups?

Post by cormack12 »

Thanks that worked - it was the Vi/Hv confusion.

I'll let the blog author know. The Hyper-v specific link directs to a zip file with two files in there called

VeeamZIP(HV).ps1
VeeamZIP(Updated).ps1

As they both dangled off the Hyper-v link in the article I assumed the (Updated) one was the most up to date version of the HyperV variant, and the VMWare one was just in the body of the article.

Oh well, sorted now. Thanks for the help.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell script failing for scripted backups?

Post by veremin »

Actually, I'm the author of the script, as well as, the said blog post. :)

The correct script for HV environments is called VeeamZIP(HV).ps1 and uses the proper commandlets (Find-VBRHvEntity, etc.). Glad that you've figured it out already.

Thanks.
Post Reply

Who is online

Users browsing this forum: caleb.boyd and 24 guests