PowerShell script exchange
Post Reply
Andreas Neufert
VP, Product Management
Posts: 6747
Liked: 1408 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Andys scripting corner - Add VM to Job/Create job and add VM

Post by Andreas Neufert » 1 person likes this post

Hi everybody,

next step at my scripting corner. Bring all example code together.
Maybe that fits not your demand, but you can use it as a code example library. :mrgreen:

What this script does:
Add VM to job and set VSS
If the job not exist.
- It creates the job
- set a repository with the highest free space
- set restore point amount
- set VSS settings (Default and VM) (deselectable)
- Enables Scheduler for Daily Backup (adjustable)

Error handlings included

Code:

Code: Select all

#############################################################################################################
#                                                                                                           
# Veeam                                                                              
#                                                                                                           
# Author: Andreas Neufert - Systems Engineer Central EMEA (Germany)                                                                                   
#                                                                                                           
# March 2012
#
# Version 2.03                                                                                                
#                                                                                                           
# ./AddVM-V2.ps1
#
# Description:
# Add VM to job and set VSS                                                                                                                                                                       
# If the job not exist. 
# - It creates the job 
# - set a repository with the highest free space
# - set restore point amount
# - set VSS settings (Default and VM) (deselectable)
# - Enables Scheduler for Daily Backup (adjustable) 
#
#Error handlings included                                                                        
#
###################################################################

#############################################################################################################
#                                                                                                       
#############################################################################################################
#Manual Input (With input validation)
$VM = "Exchange2"
$VSSEnabled = "True" #True/False
$Username = "Administrator"
$Password = "Test"
$Domain = "demolab"
$CreateJobName = "Rep001-002-auto-Win2008-XX"

############################################################################################################
# Editable Settings (be carefull => no input validation)

$VCenter = "vcenter.demolab.an.veeam.de" #vCenter/ESX-Host that was added to B&R Console - as displayed in the B&R Console

$RetainCyclesadd = "3" # Restore Points
$RetainDaysadd = "5" # VM deleted retention period in days


$VSSDefaultUsername = "Username"
$VSSDefaultPassword = "Password"
$VSSDefaultDomain = "Domain"
$SetResultsToVmNotesadd = "True" #Write Results to VM description/custom field
$VmAttributeNameadd = "BackupNotes" #Write Results to VM description/custom field

#Scheduler
$EnableScheduler = "True" #True/False
$RetrySpecifiedAdd = "True" #True/False
$RetryTimesAdd = "2"
$RetryTimeoutAdd = "22"
$OptionsDailyAddKind = "SelectedDays" #Everyday/SelectedDays/WeekDays
$OptionsDailyAddDays = "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday"
$OptionsDailyAddTime = "22:10:00" 
#Attention: If you set a time earlier than now, the job will start at the next selected Weekday

############################################################################################################
# Hardcoded Settings (do not change => Other settings than these are not considered in the code)
$Algorithmadd = "Syntethic" #Syntethic means ReverseIncremental
$SourceProxyAutoDetectadd = "True" #Automatic Proxy Selection
$schedulemode = "Daily" #Daily/Monthly/Periodically/Continuous
$MaximumErrorCount = 1000
$VSSEnabledadd = "True" #True => Development switch


 

#############################################################################################################
# Empty lines to see every code in the powershellwindow (jump under Powershellprozessing bar)
Write-host ". "
Write-host ". "
Write-host ". "
Write-host ". "
Write-host ". "
Write-host ". "
Write-host ". "
Write-host ". "
Write-host ". "
Write-host ". "
Write-host ". "

#Set Starttime
$StartTime = get-date -format u
write-host $StartTime "Information: Start time:" $StartTime



#Loads Veeam Powershell Snapin
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
$ActualDate = get-date -format u
write-host $ActualDate "Information: Veeam Powershell plugin loaded"

#Reset Error Counter
$Resultcounter = 0
$error.clear()
$ActualDate = get-date -format u
write-host $ActualDate "Information: Error counter reseted"



#Check if jobname is empty
# =>IF 2<=
if  ($CreateJobName -eq "") {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: Jobname is empty."

# =>IF 2<=
} ELSE {
Write-host $ActualDate "Information: Jobname not empty."

#Check if jobname exists
$JobnameObject = Get-VBRJob | Where {$_.Name -eq $CreateJobName}
# =>IF 1<=
if  ($JobnameObject -eq $Null)  {

$ActualDate = get-date -format u
Write-host $ActualDate "Information: Jobname does not exist. Jobname: " $CreateJobName
Write-host $ActualDate "Information: Starting job creation for: " $CreateJobName


#Search for the Repository with the highest free space.
$ActualDate = get-date -format u
Write-host $ActualDate "Information: Search for the Repository with the highest free space"
$Repository1 = Get-VBRBackupRepository
$b = "0"
foreach ($RepositoryNames in $Repository1) {
$r = Get-VBRBackupRepository -name $RepositoryNames.name
$rServer = $r.GetHost()
$FileCommander = [Veeam.Backup.Core.CRemoteWinFileCommander]::Create($rServer.Info)
$storage = $FileCommander.GetDrives([ref]$null) | ?{$_.Name -eq $r.Path.Substring(0,3)}
$outputObj = [Math]::Round([Decimal]$storage.FreeSpace/1GB,0)
$ia = $RepositoryNames.name
If ($ia -eq "Default Backup Repository") {
$outputObj = 0
$ActualDate = get-date -format u
Write-host $ActualDate "Information: Repository:" $ia "manually set to 0GB free space (disabled)"
} ELSE {}
$ib = $outputObj
$ActualDate = get-date -format u
write-host $ActualDate "Information: Repository: " $ia " with "$ib "GB free space"

if ($ib -ge $b) {
$b = $ib
$a = $ia
} ELSE {
}
}
$ActualDate = get-date -format u
write-host $ActualDate "Information: Selected Repository:" $a " with " $b "GB free space"




#Check if VCenter/ESX exists
$vbrserverVC = Get-VBRServer | where {$_.Name -eq $VCenter}
# =>IF 9<=
if  ($vbrserverVC -eq $Null)  {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: vcenter/ESX name not correct. vcenter/ESX: " $VCenter
# =>IF 9<=
} Else {
$ActualDate = get-date -format u
Write-host $ActualDate "Information: vcenter/ESX name accepted. vcenter/ESX: " $VCenter

#Check if VM exists
$vbrobjects = Find-VBRObject $vbrserverVC | ?{$_.name -eq $VM}
# =>IF 10<=
if  ($vbrobjects -eq $Null)  {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: VM does not exist. VM Name: " $VM
# =>IF 10<=
} Else {
$ActualDate = get-date -format u
Write-host $ActualDate  "Information: VM exists. VM Name: " $VM

#Create job

$ActualDate = get-date -format u
Write-host $ActualDate  "Information: Create job " $CreateJobName " please wait..."

$CreateJobRep = Get-VBRBackupRepository -Name $a
$CreateJobVM = Find-VBRViEntity -Server $vbrserverVC -Name $VM
Add-VBRViBackupJob -Name $CreateJobName -BackupRepository $CreateJobRep -Entity $CreateJobVM

#Check if job name exists
$JobnameObject = Get-VBRJob | Where {$_.Name -eq $CreateJobName}
# =>IF 11<=
if  ($JobnameObject -eq $Null)  {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: Job was not created. Jobname: " $CreateJobName 
# =>IF 11<=
} Else {
$ActualDate = get-date -format u
Write-host $ActualDate "Information: Job" $CreateJobName "succesfully created." 


#Set Job Options
$JobnameObjectOptions = $JobnameObject.GetOptions()
$JobnameObjectOptions.BackupStorageOptions.RetainCycles = $RetainCyclesadd
$JobnameObjectOptions.JobOptions.SourceProxyAutoDetect = $SourceProxyAutoDetectadd
$JobnameObjectOptions.BackupStorageOptions.RetainDays = $RetainDaysadd
$JobnameObjectOptions.ViSourceOptions.SetResultsToVmNotes = $SetResultsToVmNotesadd
$JobnameObjectOptions.ViSourceOptions.VmAttributeName = $VmAttributeNameadd
$JobnameObjectOptions.BackupTargetOptions.Algorithm = $Algorithmadd
$JobnameObject.setoptions($JobnameObjectOptions)
$ActualDate = get-date -format u
Write-host $ActualDate "Information: Job options set"



# Set Scheduling Options
$JobnameObject = Get-VBRJob | Where {$_.Name -eq $CreateJobName}
$JobnameObjectSchedule = $JobnameObject | Get-VBRjobscheduleoptions
If ($RetrySpecifiedAdd -eq "True"){
$JobnameObjectSchedule.RetrySpecified = $true
} ELSE {
$JobnameObjectSchedule.RetrySpecified = $false
}
$JobnameObjectSchedule.RetryTimes = $RetryTimesAdd  
$JobnameObjectSchedule.RetryTimeout = $RetryTimeoutAdd
If ($schedulemode -eq "Daily"){
$JobnameObjectSchedule.OptionsDaily.Enabled = $true
$JobnameObjectSchedule.OptionsMonthly.Enabled = $false
$JobnameObjectSchedule.OptionsPeriodically.Enabled = $false
$JobnameObjectSchedule.OptionsContinuous.Enabled = $false
} ELSE {
If ($schedulemode -eq "Monthly"){
$JobnameObjectSchedule.OptionsDaily.Enabled = $false
$JobnameObjectSchedule.OptionsMonthly.Enabled = $true
$JobnameObjectSchedule.OptionsPeriodically.Enabled = $false
$JobnameObjectSchedule.OptionsContinuous.Enabled = $false
} ELSE {
If ($schedulemode -eq "Periodically"){
$JobnameObjectSchedule.OptionsDaily.Enabled = $false
$JobnameObjectSchedule.OptionsMonthly.Enabled = $false
$JobnameObjectSchedule.OptionsPeriodically.Enabled = $true
$JobnameObjectSchedule.OptionsContinuous.Enabled = $false
} ELSE {
If ($schedulemode -eq "Continuous"){
$JobnameObjectSchedule.OptionsDaily.Enabled = $false
$JobnameObjectSchedule.OptionsMonthly.Enabled = $false
$JobnameObjectSchedule.OptionsPeriodically.Enabled = $false
$JobnameObjectSchedule.OptionsContinuous.Enabled = $true
} ELSE {
$ActualDate = get-date -format u
write-host $ActualDate "Error: Schedulemode entry not correct"
}}}}

$JobnameObjectSchedule.OptionsDaily.Kind = $OptionsDailyAddKind
$JobnameObjectSchedule.OptionsDaily.Days = $OptionsDailyAddDays
$JobnameObjectSchedule.OptionsDaily.Time = $OptionsDailyAddTime
$JobnameObjectSchedule.NextRun = $OptionsDailyAddTime
$JobnameObjectSchedule.StartDateTime = $OptionsDailyAddTime
Set-VBRJobScheduleOptions -Job $JobnameObject -Options $JobnameObjectSchedule


#$JobnameObject = Get-VBRJob | Where {$_.Name -eq $CreateJobName}
If ($EnableScheduler -eq "True"){
$JobnameObject.options.JobOptions.RunManually = $false
$JobnameObject.EnableScheduler()
} ELSE {
$JobnameObject.options.JobOptions.RunManually = $true
$JobnameObject.DisableScheduler()
}

$ActualDate = get-date -format u
Write-host $ActualDate "Information: Job scheduling options set"


# =>IF 41<=
If ($VSSEnabled -eq "True") {
$ActualDate = get-date -format u
Write-host $ActualDate "Information: VSS is enabled"

#Set VSS Default credentials
$jobnameobject = Get-VBRJob -Name $CreateJobName
$jobnameobjectVSS = $jobnameobject | Get-VBRJobVSSOptions
$credVSSDefault1 = "$VSSDefaultDomain\$VSSDefaultUsername"
$credVSSDefault2 = "$VSSDefaultPassword"
$CredentialsVSSDefault = New-Object -TypeName Veeam.Backup.Common.CCredentials -ArgumentList $credVSSDefault1,$credVSSDefault2,0,0
$jobnameobjectVSS.Credentials = $CredentialsVSSDefault
$jobnameobject | Set-VBRJobVssOptions -Options $jobnameobjectVSS
$ActualDate = get-date -format u
Write-host $ActualDate "Information: VSS Default Options set"

#Enable VSS
$JobnameObjectOptionsVSS = $JobnameObject.GetVSSOptions()
$JobnameObjectOptionsVSS.Enabled = $VSSEnabledadd
$JobnameObject.setVSSoptions($JobnameObjectOptionsVSS)
$ActualDate = get-date -format u
Write-host $ActualDate "Information: VSS Enabled"

#Set VM VSS credentials
#Check if Domain Username and Passwort isn´t empty
# =>IF 31<=
if  ($Domain -eq "") {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: VSS Domain not set"
# =>IF 31<=
} ELSE{
# =>IF 32<=
if  ($Username -eq "") {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: VSS Username not set"
# =>IF 32<=
} ELSE{
# =>IF 33<=
if  ($Password -eq "") {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: VSS Password not set"
# =>IF 33<=
} ELSE{

#Set VSS VM credentials
$VMLoaded = Get-VBRJob -Name $CreateJobName | Get-VBRJobObject -Name $VM
$cred1 = "$Domain\$Username"
$cred2 = "$Password"
$Credentials = New-Object -TypeName Veeam.Backup.Common.CCredentials -ArgumentList $cred1,$cred2,0,0
$VSSJobOptions = $JobnameObject.GetVssOptions()
$VSSJobOptions.Credentials = $Credentials
Set-VBRJobObjectVssOptions -object $VMLoaded -options $VSSJobOptions

$ActualDate = get-date -format u
Write-host $ActualDate "Information: VSS VM credentials set"


$ActualDate = get-date -format u
Write-host $ActualDate "Information: Finished with job options"

# =>IF 33<=
}
# =>IF 32<=
}
# =>IF 31<=
}

# =>IF 41<=
} ELSE { 
$ActualDate = get-date -format u
Write-host $ActualDate "Information: VSS is disabled"
$ActualDate = get-date -format u
Write-host $ActualDate "Information: Finished with job options"
# =>IF 41<=
}


# =>IF 11<=
}
# =>IF 10<=
}
# =>IF 9<=
}


# =>IF 1<=
} Else {

$ActualDate = get-date -format u
Write-host $ActualDate "Information: Jobname is" $CreateJobName

#Check if job name exists
$ActualDate = get-date -format u
Write-host $ActualDate "Information: Jobname name accepted. Jobname: " $CreateJobName

#Check if VCenter/ESX exists
$vbrserverVC = Get-VBRServer | where {$_.Name -eq $VCenter}
# =>IF 3<=
if  ($vbrserverVC -eq $Null)  {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: vcenter/ESX name not correct. vcenter/ESX: " $VCenter
# =>IF 3<=
} Else {
$ActualDate = get-date -format u
Write-host $ActualDate "Information: vcenter/ESX name accepted. vcenter/ESX: " $vcenter

#Check if VM exists
$vbrobjects = Find-VBRObject $vbrserverVC | ?{$_.name -eq $VM}
# =>IF 4<=
if  ($vbrobjects -eq $Null)  {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: VM does not exist. VM Name: " $VM
# =>IF 4<=
} Else {
$ActualDate = get-date -format u
Write-host $ActualDate  "Information: VM exists. VM Name: " $VM

#Add VM to Job
$ActualDate = get-date -format u
Write-host $ActualDate  "Information: Adding " $VM " to Job " $CreateJobName
Add-VBRJobObject -Job $JobnameObject -Server $vbrserverVC -Object $vbrobjects

#Check if VM was sucessfully added
$ActualDate = get-date -format u
write-host $ActualDate "Information: Start proofcheck"
$tt = Get-VBRJob -Name $JobnameObject | Get-VBRJobObject | where {$_.name -eq $VM}
$erg = $VM -notmatch $tt.Name
$ActualDate = get-date -format u
#write-host $ActualDate "Information: Proofcheck result:" $erg
# =>IF 5<=
IF ($erg -eq "True") {
$resultcounter++
$ActualDate = get-date -format u
write-host $ActualDate "Error: " $VM "not added to job " $CreateJobName
# =>IF 5<=
} ELSE  {
$ActualDate = get-date -format u
write-host $ActualDate "Information: Successfully added: " $VM

# =>IF 42<=
If ($VSSEnabled -eq "True") {
$ActualDate = get-date -format u
Write-host $ActualDate "Information: VSS is enabled"

#Set VM VSS credentials
#Check if Domain Username and Passwort isn´t empty
# =>IF 6<=
if  ($Domain -eq "") {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: VSS Domain not set"
# =>IF 6<=
} ELSE{
# =>IF 7<=
if  ($Username -eq "") {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: VSS Username not set"
# =>IF 7<=
} ELSE{
# =>IF 8<=
if  ($Password -eq "") {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: VSS Password not set"
# =>IF 8<=
} ELSE{
$cred1 = "$Domain\$Username"
$cred2 = "$Password"
$VMLoaded = Get-VBRJob -Name $CreateJobName | Get-VBRJobObject -Name $VM
$Credentials = New-Object -TypeName Veeam.Backup.Common.CCredentials -ArgumentList $cred1,$cred2,0,0
$VSSJobOptions = $VMLoaded.GetVssOptions()
$VSSJobOptions.Credentials = $Credentials
Set-VBRJobObjectVssOptions -object $VMLoaded -options $VSSJobOptions
Write-host $ActualDate "Information: VSS credentials set successfully"

# =>IF 8<=
}
# =>IF 7<=
}
# =>IF 6<=
}
# =>IF 42<=
} ELSE { 
$ActualDate = get-date -format u
Write-host $ActualDate "Information: VSS is disabled"
$ActualDate = get-date -format u
Write-host $ActualDate "Information: Finished with job options"
# =>IF 42<=
}
# =>IF 5<=
}
# =>IF 4<=
}
# =>IF 3<=
}
# =>IF 1<=
}
# =>IF 2<=
}









$Resultcounterend = $Resultcounter + $error.count

#Results
IF ($Resultcounterend -lt 1)
{
write-host "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
write-host "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
write-host "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
write-host "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" 
write-host "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" 
$ActualDate = get-date -format u
Write-host $ActualDate "Information: Job started at " $StartTime
Write-host $ActualDate "Information: Job finished at " $ActualDate
write-host $ActualDate "Information: Job Finished successfully"
write-host "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
write-host "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
}
ELSE
{
write-host "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
write-host "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
write-host "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
write-host "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" 
write-host "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
$ActualDate = get-date -format u
Write-host $ActualDate "Information: Job started at " $StartTime
Write-host $ActualDate "Information: Job finished at " $ActualDate
Write-host $ActualDate "Information: ERROR ERROR ERROR ERROR ERROR ERROR ERROR"
Write-host $ActualDate "Error: There are " $Resultcounterend "Errors"
Write-host $ActualDate "Error: Job Finished with Errors"
Write-host "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"    
}

#End
Example output ( if job doesn´t exists):

Code: Select all

PS C:\Dokumente und Einstellungen\Administrator> E:\scripts\AddVM-V2.ps1
. 
. 
. 
. 
. 
. 
. 
. 
. 
. 
. 
2012-04-12 22:24:51Z Information: Start time: 2012-04-12 22:24:51Z
2012-04-12 22:24:51Z Information: Veeam Powershell plugin loaded
2012-04-12 22:24:51Z Information: Error counter reseted
2012-04-12 22:24:51Z Information: Jobname not empty.
2012-04-12 22:24:55Z Information: Jobname does not exist. Jobname:  Rep001-002-auto-Win2008-XX
2012-04-12 22:24:55Z Information: Starting job creation for:  Rep001-002-auto-Win2008-XX
2012-04-12 22:24:55Z Information: Search for the Repository with the highest free space
2012-04-12 22:25:03Z Information: Repository:  backup  with  63 GB free space
2012-04-12 22:25:08Z Information: Repository: Default Backup Repository manually set to 0GB free space (disabled)
2012-04-12 22:25:08Z Information: Repository:  Default Backup Repository  with  0 GB free space
2012-04-12 22:25:08Z Information: Selected Repository: backup  with  63 GB free space
2012-04-12 22:25:12Z Information: vcenter/ESX name accepted. vcenter/ESX:  vcenter.demolab.an.veeam.de
2012-04-12 22:25:18Z Information: VM exists. VM Name:  Exchange2
2012-04-12 22:25:18Z Information: Create job  Rep001-002-auto-Win2008-XX  please wait...


Id                     : 54637a7d-553a-45a8-8b7f-ddbf26bcf66f
Info                   : Veeam.Backup.Model.CDbBackupJobInfo
JobType                : Backup
SourceType             : VDDK
JobTargetType          : Backup
TargetType             : Other
TypeToString           : VMware Backup
Description            : Created by Powershell at 12.04.2012 22:25:27.
Name                   : Rep001-002-auto-Win2008-XX
BackupPlatform         : EVmware
TargetHostId           : 6745a759-2205-4cd2-b172-8ec8f7e60ef8
TargetDir              : E:\BackupRepository1
TargetFile             : Rep001-002-auto-Win2008-XX
Options                : Veeam.Backup.Model.CJobOptions
IsContinuous           : False
HvReplicaTargetOptions : Veeam.Backup.Model.CDomHvReplicaTargetOptions
BackupStorageOptions   : Veeam.Backup.Model.CDomBackupStorageOptions
BackupTargetOptions    : Veeam.Backup.Model.CDomBackupTargetOptions
HvSourceOptions        : Veeam.Backup.Model.CDomHvSourceOptions
JobOptions             : Veeam.Backup.Model.CDomJobOptions
NotificationOptions    : Veeam.Backup.Model.CDomNotificationOptions
PostJobCommand         : Veeam.Backup.Model.CDomPostJobCommand
ViReplicaTargetOptions : Veeam.Backup.Model.CDomViReplicaTargetOptions
ViSourceOptions        : Veeam.Backup.Model.CDomViSourceOptions
VssOptions             : <CVssOptions><Enabled>False</Enabled><IgnoreErrors>True</IgnoreErrors><GuestFSIndexingType>Non
                         e</GuestFSIndexingType><TransactionLogsTruncation>Never</TransactionLogsTruncation><IsFirstUsa
                         ge>True</IsFirstUsage><IncludedIndexingFolders /><ExcludedIndexingFolders><string>%windir%</st
                         ring><string>%ProgramFiles%</string><string>%TEMP%</string></ExcludedIndexingFolders></CVssOpt
                         ions>
ScheduleOptions        : Start time: [12.04.2012 22:30:31], Latest run time: [12.04.2012 22:25:31], Next run time: [], 
                         Retry times on failure: [3], Retry timeout: [10 min], Daily options: [Enabled: True, DayNumber
                         InMonth: Everyday, Days: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday]Monthl
                         y options: [Enabled: False, Time: 12.04.2012 22:00:00, Day Number In Month: Fourth, Day Of Wee
                         k: Saturday, Months: January, February, March, April, May, June, July, August, September, Octo
                         ber, November, December]Periodically options: [Enabled: False, Period: 1 hour(s), ScheduleStri
                         ng: <scheduler><Sunday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Sunday><Monday>0,0,0,0
                         ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Monday><Tuesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                         0,0,0,0,0,0</Tuesday><Wednesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Wednesday><Th
                         ursday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Thursday><Friday>0,0,0,0,0,0,0,0,0,0,0
                         ,0,0,0,0,0,0,0,0,0,0,0,0,0</Friday><Saturday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</
                         Saturday></scheduler>]Continuous options: [Enabled: False]
IsScheduleEnabled      : True
IsInitialReplica       : False
IsBackup               : True
IsSnapshotReplica      : False
IsLegacyReplica        : False
IsReplica              : False
IsVmCopy               : False

2012-04-12 22:25:35Z Information: Job Rep001-002-auto-Win2008-XX succesfully created.
2012-04-12 22:25:35Z Information: Job options set
Id                     : 54637a7d-553a-45a8-8b7f-ddbf26bcf66f
Info                   : Veeam.Backup.Model.CDbBackupJobInfo
JobType                : Backup
SourceType             : VDDK
JobTargetType          : Backup
TargetType             : Other
TypeToString           : VMware Backup
Description            : Created by Powershell at 12.04.2012 22:25:27.
Name                   : Rep001-002-auto-Win2008-XX
BackupPlatform         : EVmware
TargetHostId           : 6745a759-2205-4cd2-b172-8ec8f7e60ef8
TargetDir              : E:\BackupRepository1
TargetFile             : Rep001-002-auto-Win2008-XX
Options                : Veeam.Backup.Model.CJobOptions
IsContinuous           : False
HvReplicaTargetOptions : Veeam.Backup.Model.CDomHvReplicaTargetOptions
BackupStorageOptions   : Veeam.Backup.Model.CDomBackupStorageOptions
BackupTargetOptions    : Veeam.Backup.Model.CDomBackupTargetOptions
HvSourceOptions        : Veeam.Backup.Model.CDomHvSourceOptions
JobOptions             : Veeam.Backup.Model.CDomJobOptions
NotificationOptions    : Veeam.Backup.Model.CDomNotificationOptions
PostJobCommand         : Veeam.Backup.Model.CDomPostJobCommand
ViReplicaTargetOptions : Veeam.Backup.Model.CDomViReplicaTargetOptions
ViSourceOptions        : Veeam.Backup.Model.CDomViSourceOptions
VssOptions             : <CVssOptions><Enabled>False</Enabled><IgnoreErrors>True</IgnoreErrors><GuestFSIndexingType>Non
                         e</GuestFSIndexingType><TransactionLogsTruncation>Never</TransactionLogsTruncation><IsFirstUsa
                         ge>True</IsFirstUsage><IncludedIndexingFolders /><ExcludedIndexingFolders><string>%windir%</st
                         ring><string>%ProgramFiles%</string><string>%TEMP%</string></ExcludedIndexingFolders></CVssOpt
                         ions>
ScheduleOptions        : Start time: [12.04.2012 22:10:00], Latest run time: [12.04.2012 22:25:31], Next run time: [22:
                         10:00], Retry times on failure: [2], Retry timeout: [22 min], Daily options: [Enabled: True, D
                         ayNumberInMonth: SelectedDays, Days: Monday, Tuesday, Wednesday, Thursday, Friday]Monthly opti
                         ons: [Enabled: False, Time: 12.04.2012 22:00:00, Day Number In Month: Fourth, Day Of Week: Sat
                         urday, Months: January, February, March, April, May, June, July, August, September, October, N
                         ovember, December]Periodically options: [Enabled: False, Period: 1 hour(s), ScheduleString: <s
                         cheduler><Sunday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Sunday><Monday>0,0,0,0,0,0,0
                         ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Monday><Tuesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                         0,0,0</Tuesday><Wednesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Wednesday><Thursday
                         >0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Thursday><Friday>0,0,0,0,0,0,0,0,0,0,0,0,0,0
                         ,0,0,0,0,0,0,0,0,0,0</Friday><Saturday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Saturd
                         ay></scheduler>]Continuous options: [Enabled: False]
IsScheduleEnabled      : True
IsInitialReplica       : False
IsBackup               : True
IsSnapshotReplica      : False
IsLegacyReplica        : False
IsReplica              : False
IsVmCopy               : False

2012-04-12 22:25:47Z Information: Job scheduling options set
2012-04-12 22:25:47Z Information: VSS is enabled
Id                     : 54637a7d-553a-45a8-8b7f-ddbf26bcf66f
Info                   : Veeam.Backup.Model.CDbBackupJobInfo
JobType                : Backup
SourceType             : VDDK
JobTargetType          : Backup
TargetType             : Other
TypeToString           : VMware Backup
Description            : Created by Powershell at 12.04.2012 22:25:27.
Name                   : Rep001-002-auto-Win2008-XX
BackupPlatform         : EVmware
TargetHostId           : 6745a759-2205-4cd2-b172-8ec8f7e60ef8
TargetDir              : E:\BackupRepository1
TargetFile             : Rep001-002-auto-Win2008-XX
Options                : Veeam.Backup.Model.CJobOptions
IsContinuous           : False
HvReplicaTargetOptions : Veeam.Backup.Model.CDomHvReplicaTargetOptions
BackupStorageOptions   : Veeam.Backup.Model.CDomBackupStorageOptions
BackupTargetOptions    : Veeam.Backup.Model.CDomBackupTargetOptions
HvSourceOptions        : Veeam.Backup.Model.CDomHvSourceOptions
JobOptions             : Veeam.Backup.Model.CDomJobOptions
NotificationOptions    : Veeam.Backup.Model.CDomNotificationOptions
PostJobCommand         : Veeam.Backup.Model.CDomPostJobCommand
ViReplicaTargetOptions : Veeam.Backup.Model.CDomViReplicaTargetOptions
ViSourceOptions        : Veeam.Backup.Model.CDomViSourceOptions
VssOptions             : <CVssOptions><Enabled>False</Enabled><IgnoreErrors>True</IgnoreErrors><GuestFSIndexingType>Non
                         e</GuestFSIndexingType><Credentials><UserName>Domain\Username</UserName><Password>AQAAANCMnd8B
                         FdERjHoAwE/Cl+sBAAAAVgWsSXAIVkCUHMX+Pm+sHgAAAAACAAAAAAADZgAAqAAAABAAAAAxAC6zjyCSm+pRi6BowX8dAA
                         AAAASAAACgAAAAEAAAAJMEErbFIFdq+D7/zUZ+pZMQAAAAc425PK66ueb8OlAL0amStxQAAAC6IhiLQlpsTZV0EfEK68Gx
                         VILlmA==</Password><IsLocalProtect>False</IsLocalProtect><CurrentUser>False</CurrentUser></Cre
                         dentials><TransactionLogsTruncation>Never</TransactionLogsTruncation><IsFirstUsage>True</IsFir
                         stUsage><IncludedIndexingFolders /><ExcludedIndexingFolders><string>%windir%</string><string>%
                         ProgramFiles%</string><string>%TEMP%</string></ExcludedIndexingFolders></CVssOptions>
ScheduleOptions        : Start time: [12.04.2012 22:10:00], Latest run time: [12.04.2012 22:25:31], Next run time: [22:
                         10:00], Retry times on failure: [2], Retry timeout: [22 min], Daily options: [Enabled: True, D
                         ayNumberInMonth: SelectedDays, Days: Monday, Tuesday, Wednesday, Thursday, Friday]Monthly opti
                         ons: [Enabled: False, Time: 12.04.2012 22:00:00, Day Number In Month: Fourth, Day Of Week: Sat
                         urday, Months: January, February, March, April, May, June, July, August, September, October, N
                         ovember, December]Periodically options: [Enabled: False, Period: 1 hour(s), ScheduleString: <s
                         cheduler><Sunday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Sunday><Monday>0,0,0,0,0,0,0
                         ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Monday><Tuesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                         0,0,0</Tuesday><Wednesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Wednesday><Thursday
                         >0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Thursday><Friday>0,0,0,0,0,0,0,0,0,0,0,0,0,0
                         ,0,0,0,0,0,0,0,0,0,0</Friday><Saturday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Saturd
                         ay></scheduler>]Continuous options: [Enabled: False]
IsScheduleEnabled      : True
IsInitialReplica       : False
IsBackup               : True
IsSnapshotReplica      : False
IsLegacyReplica        : False
IsReplica              : False
IsVmCopy               : False

2012-04-12 22:26:00Z Information: VSS Default Options set
2012-04-12 22:26:00Z Information: VSS Enabled
Id                  : a41846fc-622d-4530-8781-3abffd5b3770
Object              : Name: Exchange2
Filter              : 
Name                : Exchange2
Type                : Include
Location            : vcenter.demolab.an.veeam.de\demolab\demolab Cluster\Produktiv\Exchange2
ApproxSizeString    : 0,0 KB
Info                : Veeam.Backup.Model.CDbObjectInJobInfo
JobId               : 54637a7d-553a-45a8-8b7f-ddbf26bcf66f
IsFolder            : False
IsIncluded          : True
IsVssChild          : False
IsExcludeDisksChild : False
IsExcluded          : False
IsExtended          : False
PolicyType          : None
VssOptions          : <CVssOptions><Enabled>True</Enabled><IgnoreErrors>True</IgnoreErrors><GuestFSIndexingType>None</G
                      uestFSIndexingType><Credentials><UserName>demolab\Administrator</UserName><Password>AQAAANCMnd8BF
                      dERjHoAwE/Cl+sBAAAAVgWsSXAIVkCUHMX+Pm+sHgAAAAACAAAAAAADZgAAqAAAABAAAABvRRRE2VUGjYHFpiAa71gSAAAAAA
                      SAAACgAAAAEAAAAJmJ4LXJmbsAwxiBT2Dm4cIIAAAAvpoTVZ8ElnoUAAAAJhYRDFmwsEPLY4LhJzCh4zSe1pY=</Password>
                      <IsLocalProtect>False</IsLocalProtect><CurrentUser>False</CurrentUser></Credentials><TransactionL
                      ogsTruncation>Never</TransactionLogsTruncation><IsFirstUsage>True</IsFirstUsage><IncludedIndexing
                      Folders /><ExcludedIndexingFolders><string>%windir%</string><string>%ProgramFiles%</string><strin
                      g>%TEMP%</string></ExcludedIndexingFolders></CVssOptions>
ExtendedOptions     : Veeam.Backup.Model.COijExtendedOptions
DiskFilter          : 2000;2001;2002;2003;2004;2005;2006;2008;2009;2010;2011;2012;2013;2014;2015;2016;2017;2018;2019;20
                      20;2021;2022;2024;2025;2026;2027;2028;2029;2030;2031;2032;2033;2034;2035;2036;2037;2038;2040;2041
                      ;2042;2043;2044;2045;2046;2047;2048;2049;2050;2051;2052;2053;2054;2056;2057;2058;2059;2060;2061;2
                      062;2063
UpdateConfig        : True

2012-04-12 22:26:12Z Information: VSS VM credentials set
2012-04-12 22:26:12Z Information: Finished with job options
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2012-04-12 22:26:12Z Information: Job started at  2012-04-12 22:24:51Z
2012-04-12 22:26:12Z Information: Job finished at  2012-04-12 22:26:12Z
2012-04-12 22:26:12Z Information: Job Finished successfully
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Example output (when job already exists):

Code: Select all

PS C:\Dokumente und Einstellungen\Administrator> E:\scripts\AddVM-V2.ps1
. 
. 
. 
. 
. 
. 
. 
. 
. 
. 
. 
2012-04-12 22:28:41Z Information: Start time: 2012-04-12 22:28:41Z
2012-04-12 22:28:41Z Information: Veeam Powershell plugin loaded
2012-04-12 22:28:41Z Information: Error counter reseted
2012-04-12 22:28:41Z Information: Jobname not empty.
2012-04-12 22:28:45Z Information: Jobname is Rep001-002-auto-Win2008-XX
2012-04-12 22:28:45Z Information: Jobname name accepted. Jobname:  Rep001-002-auto-Win2008-XX
2012-04-12 22:28:49Z Information: vcenter/ESX name accepted. vcenter/ESX:  vcenter.demolab.an.veeam.de
2012-04-12 22:28:54Z Information: VM exists. VM Name:  Exchange2
2012-04-12 22:28:54Z Information: Adding  Exchange2  to Job  Rep001-002-auto-Win2008-XX


Id                  : a41846fc-622d-4530-8781-3abffd5b3770
Object              : Name: Exchange2
Filter              : 
Name                : Exchange2
Type                : Include
Location            : vcenter.demolab.an.veeam.de\demolab\demolab Cluster\Produktiv\Exchange2
ApproxSizeString    : 0,0 KB
Info                : Veeam.Backup.Model.CDbObjectInJobInfo
JobId               : 54637a7d-553a-45a8-8b7f-ddbf26bcf66f
IsFolder            : False
IsIncluded          : True
IsVssChild          : False
IsExcludeDisksChild : False
IsExcluded          : False
IsExtended          : False
PolicyType          : None
VssOptions          : <CVssOptions><Enabled>True</Enabled><IgnoreErrors>True</IgnoreErrors><GuestFSIndexingType>None</G
                      uestFSIndexingType><Credentials><UserName>demolab\Administrator</UserName><Password>AQAAANCMnd8BF
                      dERjHoAwE/Cl+sBAAAAVgWsSXAIVkCUHMX+Pm+sHgAAAAACAAAAAAADZgAAqAAAABAAAABvRRRE2VUGjYHFpiAa71gSAAAAAA
                      SAAACgAAAAEAAAAJmJ4LXJmbsAwxiBT2Dm4cIIAAAAvpoTVZ8ElnoUAAAAJhYRDFmwsEPLY4LhJzCh4zSe1pY=</Password>
                      <IsLocalProtect>False</IsLocalProtect><CurrentUser>False</CurrentUser></Credentials><TransactionL
                      ogsTruncation>Never</TransactionLogsTruncation><IsFirstUsage>True</IsFirstUsage><IncludedIndexing
                      Folders /><ExcludedIndexingFolders><string>%windir%</string><string>%ProgramFiles%</string><strin
                      g>%TEMP%</string></ExcludedIndexingFolders></CVssOptions>
ExtendedOptions     : Veeam.Backup.Model.COijExtendedOptions
DiskFilter          : 2000;2001;2002;2003;2004;2005;2006;2008;2009;2010;2011;2012;2013;2014;2015;2016;2017;2018;2019;20
                      20;2021;2022;2024;2025;2026;2027;2028;2029;2030;2031;2032;2033;2034;2035;2036;2037;2038;2040;2041
                      ;2042;2043;2044;2045;2046;2047;2048;2049;2050;2051;2052;2053;2054;2056;2057;2058;2059;2060;2061;2
                      062;2063
UpdateConfig        : True

2012-04-12 22:28:59Z Information: Start proofcheck
2012-04-12 22:29:07Z Information: Successfully added:  Exchange2
2012-04-12 22:29:07Z Information: VSS is enabled
Id                  : a41846fc-622d-4530-8781-3abffd5b3770
Object              : Name: Exchange2
Filter              : 
Name                : Exchange2
Type                : Include
Location            : vcenter.demolab.an.veeam.de\demolab\demolab Cluster\Produktiv\Exchange2
ApproxSizeString    : 0,0 KB
Info                : Veeam.Backup.Model.CDbObjectInJobInfo
JobId               : 54637a7d-553a-45a8-8b7f-ddbf26bcf66f
IsFolder            : False
IsIncluded          : True
IsVssChild          : False
IsExcludeDisksChild : False
IsExcluded          : False
IsExtended          : False
PolicyType          : None
VssOptions          : <CVssOptions><Enabled>True</Enabled><IgnoreErrors>True</IgnoreErrors><GuestFSIndexingType>None</G
                      uestFSIndexingType><Credentials><UserName>demolab\Administrator</UserName><Password>AQAAANCMnd8BF
                      dERjHoAwE/Cl+sBAAAAVgWsSXAIVkCUHMX+Pm+sHgAAAAACAAAAAAADZgAAqAAAABAAAABwLCqHG6N3Z4f7C/t3ZyP7AAAAAA
                      SAAACgAAAAEAAAAOhVqRF5rLWicNzrD8sMKlcIAAAAkPTh5OYJLRYUAAAA5eO9+QiTWyEhhQUj5JeqlFTO7Kw=</Password>
                      <IsLocalProtect>False</IsLocalProtect><CurrentUser>False</CurrentUser></Credentials><TransactionL
                      ogsTruncation>Never</TransactionLogsTruncation><IsFirstUsage>True</IsFirstUsage><IncludedIndexing
                      Folders /><ExcludedIndexingFolders><string>%windir%</string><string>%ProgramFiles%</string><strin
                      g>%TEMP%</string></ExcludedIndexingFolders></CVssOptions>
ExtendedOptions     : Veeam.Backup.Model.COijExtendedOptions
DiskFilter          : 2000;2001;2002;2003;2004;2005;2006;2008;2009;2010;2011;2012;2013;2014;2015;2016;2017;2018;2019;20
                      20;2021;2022;2024;2025;2026;2027;2028;2029;2030;2031;2032;2033;2034;2035;2036;2037;2038;2040;2041
                      ;2042;2043;2044;2045;2046;2047;2048;2049;2050;2051;2052;2053;2054;2056;2057;2058;2059;2060;2061;2
                      062;2063
UpdateConfig        : True

2012-04-12 22:29:07Z Information: VSS credentials set successfully
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2012-04-12 22:29:19Z Information: Job started at  2012-04-12 22:28:41Z
2012-04-12 22:29:19Z Information: Job finished at  2012-04-12 22:29:19Z
2012-04-12 22:29:19Z Information: Job Finished successfully
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Happy programming... Andy
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests