Skip to content

Instantly share code, notes, and snippets.

@smasterson
Last active August 29, 2015 13:56
Show Gist options
  • Save smasterson/9141509 to your computer and use it in GitHub Desktop.
Save smasterson/9141509 to your computer and use it in GitHub Desktop.
# Load Veeam snapin
Add-PsSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
Clear-Host
Write-Host "VM must be explicitly defined in the job"
Write-Host "VM can not be inherited by a folder, datastore or other object or it will get excluded as well and job will be empty."
Write-Host ""
Write-Host "Always confirm job completion via Veeam BR Console"
Write-Host ""
# Check Veeam Version (Must be v7)
If ((Get-PSSnapin VeeamPSSnapin).Version.Major -ne 7) {
Write-Host "You must be running VBR v7 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(*Note: this isn't removing the objects
# from the job)
Remove-VBRJobObject -Objects $execObjs
# Start the job only backing up the target VM
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 = $obj.GetObject().GetItem()
Add-VBRViJobObject -job $Job -Entities $Excitem
$obj.Delete() | Out-Null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment