PowerShell script exchange
Post Reply
andka16
Lurker
Posts: 1
Liked: never
Joined: Feb 07, 2012 8:36 am
Full Name: Andreas Karelius

Create job with several vms using PS

Post by andka16 »

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 "------------------------------------"
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Create job with several vms using PS

Post by Sethbartlett »

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.
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Create job with several vms using PS

Post by ThomasMc »

+1. Your building a big string and not an array
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests