Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Load Veeam snapin
Add-PsSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
Clear-Host
Write-Host "Veeam Single VM Backup Script`n"
Write-Host "Notes:"
Write-Host "VM must be explicitly defined in the job"
Write-Host "VM can not be inherited by a folder, datastore or other object"
Write-Host "else it will get excluded as well and job will be empty."
Write-Host "Always confirm job completion via Veeam BR Console!"
# Check Veeam Version (Must be v8)
If ((Get-PSSnapin VeeamPSSnapin).Version.Major -ne 8) {
Write-Host "You must be running VBR v8 to run this script...Exiting"
Exit
}
# User Input
$jobName = Read-Host "Enter Job Name"
$vmName = Read-Host "Enter VM Name"
# Find the job that has our VM
$job = Get-VBRJob | ?{$_.Name -eq $jobName}
# Get all objects in job apart from our target VM
$execObjs = $job.GetObjectsInJob() | ?{$_.Name -ne $vmName}
# Exclude the objects from the job
Remove-VBRJobObject -Objects $execObjs
# Start the job only backing up the target VM
$runJob = Start-VBRJob -Job $job
# Find the exclude job objects
$incObjs = $job.GetObjectsInJob() | ?{$_.Type -eq "Exclude"}
# Delete the exclude objects and re-add to job
foreach ($obj in $incObjs) {
$Excitem = Find-VBRViEntity -Name $obj.Name
Add-VBRViJobObject -job $Job -Entities $Excitem | Out-Null
$obj.Delete()
}
Write-Host "`nBackup Complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.