Create job with several vms using PS

PowerShell script exchange

Create job with several vms using PS

Veeam Logoby andka16 » Fri Feb 24, 2012 11:32 am

We are trying to create a veeam backup job and add several vms to it using this powershell code

The vms are specified in a .txt file

The script creates the job ok and adds one vm.... the rest of the vms are not added to the job.

Any help would be appreciated

/Andreas


#########################################################################

Add-PSSnapin VeeamPSSnapIn

# change $servers to correct path.
$servers = Import-Csv -Path "C:\Scripts\VeeamCandidates\LargeVMs.txt"
#$file

#Change $jobName to correct name.
$jobName = "LargeVMs"

#Change to correct path for backups
#$backupfolder = "\\<correct>\<path>\<to>\$jobname"
$backuprepositoryname = "<repositoryname>"

#Change to correct VI-server
$viServer = "<vi-server.domain.com>"

#Maxstorlek / jobb
$limit = 1200
[int]$control = 0
$firstObject = 0
$objectCount = 0
# Ändra ingenting nedan!
$vbrserver = Get-VBRServer | Where {$_.Type -eq "Local"}
$RepObject = Get-VBRBackupRepository -Name $backuprepositoryname
$viServerObject = Get-VBRServer -Name $viServer
#$vbrfolder = $backupfolder
$vbrfile = "$jobname.vbk"
$objects = ""
foreach ($server in $servers){
$name = $server.Name
$size = $server.ProvisionedSpaceGB
$size = $size.Split(",")
$size = $size[0]
$size = [int]$size
#$control = $control + $size
if ($control -lt $limit){
if ($firstObject -eq 0){
$ViObject = Find-VBRViEntity -Server $viServerObject -Name $name
Add-VBRViBackupJob -Name $jobname -BackupRepository $RepObject -Entity $ViObject
$firstObject++
Write-Host "Skapat backupjobbet på object: $name"
Write-Host "------------------------------------"
}
else{
if ($objectCount -eq 0){
$objects = $objects + $name
$objectCount++
}
else{
$objects = $objects + ", " + $name
}
}


}
else{
# Skriv ut till textfil
$name | Out-File "C:\Scripts\Report\ej_registrerade.txt" -Append
}
}
#$objects
$JobObject = Get-VBRJob -Name $jobName
$viServerObject = Get-VBRServer -Name "<vi-server.domain.com"
Add-VBRJobObject ($JobObject) -Server $viServerObject -Objects $objects
Write-Host "Lagt till objects: $objects"
Write-Host "------------------------------------"
andka16
Lurker
 
Posts: 1
Liked: never
Joined: Tue Feb 07, 2012 8:36 am
Full Name: Andreas Karelius

Re: Create job with several vms using PS

Veeam Logoby Sethbartlett » Fri Feb 24, 2012 2:58 pm

What does your text file look like? You are doing foreach($server in $servers) and $servers just seems to be an array/text. You then do:
Code: Select all
name = $server.Name
$size = $server.ProvisionedSpaceGB
$size = $size.Split(",")
$size = $size[0]
$size = [int]$size

I'm not sure how $server will have any of this data yet without finding the object first.
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: Create job with several vms using PS

Veeam Logoby ThomasMc » Wed Mar 14, 2012 8:27 pm

+1. Your building a big string and not an array
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 6 guests