Thank you. It works if i remove the [0], but still shows the following error, which i understand, but in some way, i assume it could be achieved without any errors, and possibly without specify the job name and repo fifteen times
Code: Select all
Add-VBRViBackupJob : Cannot validate argument on parameter 'Name'. Job with the same name already exists: TestAuto2
here is the whole script
Code: Select all
Add-PsSnapin VeeamPSSnapIn
$backup = Import-csv "C:\test\vms3.csv" -header Job,VM,Repo -Delimiter ","
foreach ($i in $backup){
$JobName = $i.Job
$Repo = $i.Repo
Add-VBRViBackupJob -Name $JobName -BackupRepository "$Repo" -Entity (Find-VBRViEntity -Name $i.VM)
foreach ($VM in $I.VM)
{
Add-VBRViJobObject -Job (Get-VBRJob -name $JobName) -Entities (Find-VBRViEntity -Name $I.VM)
}
#Set Job Options
$Job = Get-VBRJob | where {$_.name -eq $JobName}
$FullBackupMonth = "January","March", "May", "July","September","November" #Month's where you want active full backup to run
$Day = "Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday" | Get-Random #fill inn for weekdays - will randomize
$DayNumber = "First", "Second", "Third", "Fourth" | get-random #fill inn for week day number - will randomize
$JobOptions = Get-VBRJobOptions $Job
$JobOptions.BackupStorageOptions.EnableDeletedVmDataRetention = $true #Remove deleted vms data
$JobOptions.JobOptions.SourceProxyAutoDetect = $true
$JobOptions.JobOptions.RunManually = $false
$JobOptions.BackupStorageOptions.RetainDays = 14 # This is how long a deleted VMs files are retained
$JobOptions.BackupStorageOptions.EnableDeduplication = $true
$JobOptions.BackupStorageOptions.StgBlockSize = "KbBlockSize1024"
$JobOptions.BackupStorageOptions.CompressionLevel = 3
$JobOptions.BackupTargetOptions.Algorithm = "Syntethic"
#$JobOptions.BackupTargetOptions.TransformToSyntethicDays = ((Get-Date).adddays((Get-Random -Minimum 0 -Maximum 6))).dayofweek
#$JobOptions.BackupTargetOptions.TransformIncrementsToSyntethic = $true
$JobOptions.BackupStorageOptions.EnableFullBackup = $true
$JobOptions.BackupTargetOptions.FullBackupMonthlyScheduleOptions.DayOfWeek = $Day #inserts the random day Monday, Wednesday
$JobOptions.BackupTargetOptions.FullBackupMonthlyScheduleOptions.DayNumberInMonth = $DayNumber #Inserts daynumber
$JobOptions.BackupTargetOptions.FullBackupMonthlyScheduleOptions.Months = $FullBackupMonth #sets month's to perform backup
$JobOptions.BackupTargetOptions.FullBackupScheduleKind = "Monthly" #Monthly Schedule
$Job | Set-VBRJobOptions -Options $JobOptions
#Set schedule options
#Create random backup time between 6PM and 4AM
$Hours = (18,19,20,21,22,23,'00','01','02','03','04') | Get-Random | Out-String
$Minutes = "{0:D2}" -f (Get-Random '00','15','30','45') | Out-String
$Time = ($Hours+':'+$Minutes+':00').replace("`n","")
$JobScheduleOptions = Get-VBRJobScheduleOptions $Job
$JobScheduleOptions.OptionsDaily.Enabled = $true
$JobScheduleOptions.OptionsDaily.Kind = "Everyday"
$JobScheduleOptions.OptionsDaily.Time = $Time
$JobScheduleOptions.NextRun = $Time
$JobScheduleOptions.StartDateTime = $Time
$JobScheduleOptions.RetryTimeout = "15" #Number of minutes between retrys
$Job | Set-VBRJobScheduleOptions -Options $JobScheduleOptions
$Job.EnableScheduler()
#Set VSS Options
$JobVSSOptions = $Job | Get-VBRJobVSSOptions
#$VSSUSername = 'DOMAIN\USERNAME'
#$VSSPassword = 'PASSWORD'
#$VSSCredentials = New-Object -TypeName Veeam.Backup.Common.CCredentials -ArgumentList $VSSUSername,$VSSPassword,0,0
# $JobVSSOptions.Credentials = $VSSCredentials
$JobVSSOptions.Enabled = $true #enable Application aware image processing (VSS)
$JobVSSOptions.GuestFSIndexingType = "EveryFolders" #Enable guest file indexing for 1-click restore etc.
#Change default behavior per job object
foreach ($JobObject in ($Job | Get-VBRJobObject))
{
$ObjectVSSOptions = Get-VBRJobObjectVssOptions -ObjectInJob $JobObject
$ObjectVSSOptions.IgnoreErrors = $false
$JobVSSOptions.TransactionLogsTruncation = "Always"
Set-VBRJobObjectVssOptions -Object $JobObject -Options $ObjectVSSOptions
}
$Job | Set-VBRJobVssOptions -Options $JobVSSOptions
}
I am, without any issues able to add 50 servers to one job, if i use a csv "enter" seaparated with all the servers, and manually enter job name and repository, so i can do it that way also.