#
# Veeam
#
# Author: Andreas Neufert - Systems Engineer Central EMEA (Germany)
#
# March 2012
#
# Version 3.04
#
# ./AddVM-V3.ps1
#
# Description:
# Add VM to defined job and set VSS (V1)
#
# If the job not exist. (V2)
# - It creates the job (V2)
# - set a repository with the highest free space (V2)
# - set restore point amount (V2)
# - set VSS settings (Default and VM) (deselectable) (V2)
# - Enables Scheduler for Daily Backup (adjustable) (V2)
#
# If you set no jobname (V3)
# - It checks if the VM can be added to a suitable job (OS Type, Application Type, Production/Test Type) with a free slot.(V3)
# - If there is no suitable job (V3)
# - It searchs for a repository with the highest free space (V3)
# - Checks the highest job number in that repository (V3)
# - Creates a Job and set options incl. Scheduler and if neede VSS (V3)
#
#
#Error handling is included (V1, Enhanced in V2)
#
# !!!! This script doesn´t support ESX3.5 !!!!
#
################################################################################################################
# !!! This script is highly addapted for one of my customers. Several minimum requirements.
# !!! Because this script automates job building it makes only sense if you have more than 400 VMs
#
# Minimum Requirements:
#
# VM Names
# First letter: P => Productive Everything else => Test
# Second and Thrid letter: Application
# All other letters are freely definable
# Example PDB001
#
# Repositories:
# Only one repository per disk volume allowed
# Allowed Names:
# Example: REP001
# REP + sequence number
Code:
Code: Select all
#############################################################################################################
#
# Veeam
#
# Author: Andreas Neufert - Systems Engineer Central EMEA (Germany)
#
# March 2012
#
# Version 3.04
#
# ./AddVM-V3.ps1
#
# Description:
# Add VM to defined job and set VSS (V1)
#
# If the job not exist. (V2)
# - It creates the job (V2)
# - set a repository with the highest free space (V2)
# - set restore point amount (V2)
# - set VSS settings (Default and VM) (deselectable) (V2)
# - Enables Scheduler for Daily Backup (adjustable) (V2)
#
# If you set no jobname (V3)
# - It checks if the VM can be added to a suitable job (OS Type, Application Type, Production/Test Type) with a free slot.(V3)
# - If there is no suitable job (V3)
# - It searchs for a repository with the highest free space (V3)
# - Checks the highest job number in that repository (V3)
# - Creates a Job and set options incl. Scheduler and if neede VSS (V3)
#
#
#Error handling is included (V1, Enhanced in V2)
#
# !!!! This script doesn´t support ESX3.5 !!!!
#
################################################################################################################
# !!! This script is highly addapted for one of my customers. Several minimum requirements.
# !!! Because this script automates job building it makes only sense if you have more than 400 VMs
#
# Minimum Requirements:
#
# VM Names
# First letter: P => Productive Everything else => Test
# Second and Thrid letter: Application
# All other letters are freely definable
# Example PDB001
#
# Repositories:
# Only one repository per disk volume allowed
# Allowed Names:
# Example: REP001
# REP + sequence number
#
#
#
#
###################################################################
#############################################################################################################
#
#############################################################################################################
#Manual Input (With input validation). This values can also be set by an extern Script. Be carefull with the Password field type that it will be a string type.
$VM = "pASV0816" # Rules see above
$VSSEnabled = "True" #True/False
$Username = "Administrator"
$Password = "Test"
$Domain = "demolab"
$CreateJobName = "" # Empty or for example rep001-005-auto-win2008_64-as-prod
$OSName = "Win2003_64" # Allowed values defined in AllowedOSNames bellow
############################################################################################################
# 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
$MaxAmountOfVMsPerJob = "10" #1-999 but "100" not allowed. Recommended setting 10-15
$AllowedOSNames = "Win2003_64","Win2008_64","Linux"
$VMSignforProduction = "p" #VM Name first letter. Please define what is the letter for the productive VMs. All others are integrated into Test.
$SelectJobAuto = "auto" #What value stands for Jobs that will be considered in our processing. If Job Name is defined not as auto this script will not add VM to these jobs.
#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
#############################################################################################################
# Start
# 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 "") {
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ Start of Part 1 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ Start of Part 1 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ Start of Part 1 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
#Information
$ActualDate = get-date -format u
write-host $ActualDate "Information: Jobname empty... Searching for a job with an empty VM backup slot"
#Reset VM Error Counter
$VMResultcounter = 0
$ActualDate = get-date -format u
write-host $ActualDate "Information: VM counter reseted"
#Information
$ActualDate = get-date -format u
write-host $ActualDate "Information: Read out all Jobs and find the first empty job"
# Build a seach value for empty job search
$SelectJobOS = $OSName
$SelectJobAppType = $VM.Substring(1,2)
$SelectJobProdorTest = $VM.Substring(0,1)
If ($SelectJobProdorTest -eq $VMSignforProduction){
$SelectJobProdorTestResult = "prod"
} ELSE {
$SelectJobProdorTestResult = "test"
}
$SelectjobOutput = $SelectJobAuto + "-" + $SelectJobOS + "-" + $SelectJobAppType + "-" + $SelectJobProdorTestResult
$ActualDate = get-date -format u
write-host $ActualDate "Information: Job Search String is:" $SelectjobOutput
#Check if there is at minimum one job that fits the Search String.
$JobnameObjectVMCountObjects = Get-VBRJob | Where {$_.Name -match $SelectjobOutput}
# =>IF 1893<=
If ($JobnameObjectVMCountObjects -ne $Null){
$ActualDate = get-date -format u
write-host $ActualDate "Information: Found at minimum 1 job that fits the search string."
#Check if a job has a free slot for selected VM
foreach ($jobnameobjectVMCountObject in $JobnameObjectVMCountObjects) {
$jobnameobjectVMCountObjectOptions = $jobnameobjectVMCountObject.getoptions()
#If MaxAmountOfVMsPerJob is emty or or 100 set MaxAmountOfVMsPerJob
If ($jobnameobjectVMCountObjectOptions.ViSourceOptions.DoubleSnapshotThresholdMb -eq $NULL){
$jobnameobjectVMCountObjectOptions.ViSourceOptions.DoubleSnapshotThresholdMb = $MaxAmountOfVMsPerJob
$jobnameobjectVMCountObject.setoptions($jobnameobjectVMCountObjectOptions)
$ActualDate = get-date -format u
write-host $ActualDate "Information: Max amount of VMs per job not set for" $jobnameobjectVMCountObject.name "Set default setting: " $MaxAmountOfVMsPerJob
} ELSE { }
If ($jobnameobjectVMCountObjectOptions.ViSourceOptions.DoubleSnapshotThresholdMb -eq "100"){
$jobnameobjectVMCountObjectOptions.ViSourceOptions.DoubleSnapshotThresholdMb = $MaxAmountOfVMsPerJob
$jobnameobjectVMCountObject.setoptions($jobnameobjectVMCountObjectOptions)
$ActualDate = get-date -format u
write-host $ActualDate "Information: Max amount of VMs per job not set for" $jobnameobjectVMCountObject.name "Set default setting: " $MaxAmountOfVMsPerJob
} ELSE { }
#Read all VMs from the actual job
$VMsinJobObjects = Get-VBRJob -Name $jobnameobjectVMCountObject.Name
$VMsinJob = $VMsinJobObjects.GetObjectsInJob()
#Check if MaxAmountOfVMsPerJob as current VMs in the job
If ($jobnameobjectVMCountObjectOptions.ViSourceOptions.DoubleSnapshotThresholdMb -gt $VMsinJob.Length) {
$ActualDate = get-date -format u
write-host $ActualDate "Information: Adding VM to" $jobnameobjectVMCountObject.name " - Max VM:" $jobnameobjectVMCountObjectOptions.ViSourceOptions.DoubleSnapshotThresholdMb " - Number of VMs in Job:" $VMsinJob.Length
$CreateJobName = $jobnameobjectVMCountObject.name
$JobnameObject = $jobnameobjectVMCountObject
### Start of Part 1.1
### Start of Part 1.1
### Start of Part 1.1
$ActualDate = get-date -format u
Write-host $ActualDate "Information: Jobname is" $CreateJobName
#Check if VCenter/ESX exists
$vbrserverVC = Get-VBRServer | where {$_.Name -eq $VCenter}
# =>IF 93<=
if ($vbrserverVC -eq $Null) {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: vcenter/ESX name not correct. vcenter/ESX: " $VCenter
# =>IF 93<=
} 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 94<=
if ($vbrobjects -eq $Null) {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: VM does not exist. VM Name: " $VM
# =>IF 94<=
} 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 95<=
IF ($erg -eq "True") {
$resultcounter++
$ActualDate = get-date -format u
write-host $ActualDate "Error: " $VM "not added to job " $CreateJobName
# =>IF 95<=
} ELSE {
$ActualDate = get-date -format u
write-host $ActualDate "Information: Successfully added: " $VM
# =>IF 942<=
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 96<=
if ($Domain -eq "") {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: VSS Domain not set"
# =>IF 96<=
} ELSE{
# =>IF 97<=
if ($Username -eq "") {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: VSS Username not set"
# =>IF 97<=
} ELSE{
# =>IF 98<=
if ($Password -eq "") {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: VSS Password not set"
# =>IF 98<=
} 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 98<=
}
# =>IF 97<=
}
# =>IF 96<=
}
# =>IF 942<=
} 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 942<=
}
# =>IF 95<=
}
# =>IF 94<=
}
# =>IF 93<=
}
### End of Part 1.1
### End of Part 1.1
### End of Part 1.1
# Set VMresultcounter +1
$VMresultcounter++
# Breack foreachloop
break
} ELSE {
$ActualDate = get-date -format u
write-host $ActualDate "Information: No empty slot in" $jobnameobjectVMCountObject.name
}
}
# =>IF 1893<=
} ELSE {
$VMresultcounter = "0"
# =>IF 1893<=
}
# =>IF 1221<=
If ($VMresultcounter -ne "0") {
#do nothing
# =>IF 1221<=
} ELSE {
$ActualDate = get-date -format u
write-host $ActualDate "Information: No job fits the search string or no empty job slot ... Creating new job."
$ActualDate = get-date -format u
write-host $ActualDate "Information: Start creating new job"
### Start of Part 1.2
### Start of Part 1.2
### Start of Part 1.2
# =>IF 1222<=
If ($AllowedOSNames -contains $OSName) {
$ActualDate = get-date -format u
write-host $ActualDate "Information: OSName " $OSName "accepted"
# =>IF 1222<=
} ELSE {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: OSName not allowed"
# =>IF 1222<=
}
# OS-Typ prüfen ob erlaubt.
# Wenn ja
# Suche Repository mit dem meisten Platz
# Wähle die höchste Nummer und erstelle einen Job mit noch höherer Nummer.
#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"
#Identify the highest Job Number from the repository +1
$b1 = "0"
$JobsOfRepositorys = Get-VBRJob | Where {$_.Name -match $a}
foreach ($JobsOfRepository in $JobsOfRepositorys){
$c1 = $JobsOfRepository.Name.Substring(7,3)
If ($c1 -ge $b1){
$b1 = $c1
} ELSE {
#nothing
}
# close foreach
}
$ActualDate = get-date -format u
write-host $ActualDate "Information: Highest Jobnumer in Repository" $a "is: "$b1
#Build new Jobname
$b2 = ([Decimal]$b1/[Decimal]"1000")+([Decimal]"1"/[Decimal]"1000")
[String]$b3 = $b2
$CreateJobName = $a + "-" + $b3.Substring(2,3) + "-" + $SelectjobOutput
#Check if VCenter/ESX exists
$vbrserverVC = Get-VBRServer | where {$_.Name -eq $VCenter}
# =>IF 889<=
if ($vbrserverVC -eq $Null) {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: vcenter/ESX name not correct. vcenter/ESX: " $VCenter
# =>IF 889<=
} 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 8810<=
if ($vbrobjects -eq $Null) {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: VM does not exist. VM Name: " $VM
# =>IF 8810<=
} 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 8811<=
if ($JobnameObject -eq $Null) {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: Job was not created. Jobname: " $CreateJobName
# =>IF 8811<=
} 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
$jobnameobjectOptions.ViSourceOptions.DoubleSnapshotThresholdMb = $MaxAmountOfVMsPerJob
$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 8841<=
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 8831<=
if ($Domain -eq "") {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: VSS Domain not set"
# =>IF 8831<=
} ELSE{
# =>IF 8832<=
if ($Username -eq "") {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: VSS Username not set"
# =>IF 8832<=
} ELSE{
# =>IF 8833<=
if ($Password -eq "") {
$resultcounter++
$ActualDate = get-date -format u
Write-host $ActualDate "Error: VSS Password not set"
# =>IF 8833<=
} 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 8833<=
}
# =>IF 8832<=
}
# =>IF 8831<=
}
# =>IF 8841<=
} 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 8841<=
}
# =>IF 8811<=
}
# =>IF 8810<=
}
# =>IF 889<=
}
# =>IF 1221<=
}
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ End of Part 1 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ End of Part 1 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ End of Part 1 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ End of Part 1 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# =>IF 2<=
} ELSE {
Write-host $ActualDate "Information: Jobname not empty."
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ Start of Part 2 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ Start of Part 2 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ Start of Part 2 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ Start of Part 2 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
#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 {
#}
#}
$a = $CreateJobName.substring(0,6)
$ActualDate = get-date -format u
write-host $ActualDate "Information: Used Repository:" $a
#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
$jobnameobjectOptions.ViSourceOptions.DoubleSnapshotThresholdMb = $MaxAmountOfVMsPerJob
$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 {
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ End of Part 2 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ End of Part 2 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ End of Part 2 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ Start of Part 3 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ Start of Part 3 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ Start of Part 3 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ Start of Part 3 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
$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<=
}
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ End of Part 3 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ End of Part 3 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ End of Part 3 §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# =>IF 1<=
}
# =>IF 2<=
}
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ Results §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ Results §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
# §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ Results §§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
$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: VM: " $VM
Write-host $ActualDate "Information: Jobname: " $CreateJobName
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