PowerShell script exchange
Post Reply
robicon
Lurker
Posts: 2
Liked: never
Joined: Jun 04, 2013 7:54 pm
Full Name: Robbi Hatcher
Contact:

What am I doing wrong?

Post by robicon »

Code: Select all

asnp "VeeamPSSnapin"

$vmlist = Import-CSV C:\Scripts\create-servers.csv

# map out variables
$vmname = $item.name
$vcserver = $item.vcserver
$veeamjobname = "MMS-CORP"
$vbrjob = Get-VBRJob | Where {$_.Name -eq $veeamjobname}
$veeamserver = Get-VBRServer | Where {$_.Type -eq "VC"}



foreach ($item in $vmlist) {
write-host adding $item.name to Veeam Backup $item.backupjob
Add-VBRJobObject -Job $vbrjob -Server $veeamserver -Object $item.name | out-null
#just the test the varible
echo $item.backupjob  
}

This works but as soon as I replace $veeamjobname = "MMS-CORP" to $veeamjobname = item.backupjob it breaks.

here is the output

PS C:\Scripts> .\veeambu.ps1
adding dc02dbc01s04 to Veeam Backup MMS-CORP
Add-VBRJobObject : Cannot bind parameter 'Job'. Cannot convert the "MMS-CORP" value of type "System.String" to type
"Veeam.Backup.Core.CBackupJob".
At C:\Scripts\veeambu.ps1:18 char:23
+ Add-VBRJobObject -Job $veeamjobname -Server $veeamserver -Object $item.name | ou ...
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Add-VBRJobObject], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Veeam.Backup.PowerShell.Command.AddVBRJobObject

MMS-CORP
adding dc02dbc01s05 to Veeam Backup MMS-CORP
Add-VBRJobObject : Cannot bind parameter 'Job'. Cannot convert the "MMS-CORP" value of type "System.String" to type
"Veeam.Backup.Core.CBackupJob".
At C:\Scripts\veeambu.ps1:18 char:23
+ Add-VBRJobObject -Job $veeamjobname -Server $veeamserver -Object $item.name | ou ...
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Add-VBRJobObject], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Veeam.Backup.PowerShell.Command.AddVBRJobObject


any input is welcomed!
tsightler
VP, Product Management
Posts: 6009
Liked: 2843 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: What am I doing wrong?

Post by tsightler » 1 person likes this post

You can't use the $item variable outside of the loop because don't actually define it until you start the loop so you're effectively just setting these values to NULL. It works when you manually enter the job name "by chance" because you're also not using the server name to actually find the vCenter server but rather are querying all servers and then filtering on the server that is the "VC" type (vCenter) which I assume you only have one of.

You need to move your variable assign logic into the loop if you want to use the values from the list.
robicon
Lurker
Posts: 2
Liked: never
Joined: Jun 04, 2013 7:54 pm
Full Name: Robbi Hatcher
Contact:

Re: What am I doing wrong?

Post by robicon »

Thanks! that did it!

Just starting to learn powershell. This makes way more sense to me now! :)
Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests