I created a simple PowerShell function to add VM’s in a VEEAM backup job. This script has 2 options, enable indexing and/or application aware processing per object.
There are many more possibilities to add functionality. For now, it fits our needs. If you have some feature requests, please comment below.
It can be used by VMWare and Hyper-v users; it checks the hypervisor in the beginning.
Run this script on a VEEAM VBR Server.
Together we can improve this PowerShell function, don’t hesitate to comment.
Deleted some bugs 23-01-2017
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
<# .EXAMPLE First, import the function with the following command: C:\PS> . .\PS_AddVMJob Second C:\PS> ps_addvmjob -vmname NAME -Application y -Indexing y .HYPERVISOR This script can be used by VMWare and Hyper-v users, it uses commands from both hypervisors .VERION Tested with VEEAM B&R V8 and V9.5 2.0 .NOTES Author: Rob Verhees Date created: 23-1-2017 PowerShell beginner #> function PS_AddVMJob { [CmdletBinding()] param ( [parameter(Mandatory=$true,ValueFromPipeline=$true)] [string]$vmname, [parameter(Mandatory=$true,ValueFromPipeline=$true)] [ValidateSet("y","n")] [string]$application, [parameter(Mandatory=$true,ValueFromPipeline=$true)] [ValidateSet("y","n")] [string]$indexing ) Begin { If ((Get-PSSnapin -Name VeeamPSSnapin -ErrorAction SilentlyContinue) -eq $null) {add-pssnapin VeeamPSSnapin} #File indexing $Excludedfolders = @("%windir%","%ProgramFiles%","%ProgramFiles(x86)%","%ProgramW6432%","%TEMP%") #Determine the Hypervisor type $VBRServerType = Get-VBRServer | where{$_.type -match "esxi" -or $_.type -match "HvServer"} | Select -ExpandProperty Type -Last 1 } Process{ #Get VBRJobs and create a menu $jobs = Get-VBRjob | where{$_.JobType -eq 'Backup'} $menu = @{} for ($i=1;$i -le $jobs.count; $i++) { Write-Host "$i. $($jobs[$i-1].name)" $menu.Add($i,($jobs[$i-1].name)) } [int]$ans = Read-Host 'Kies back-up job:' $selection = $menu.Item($ans) $jobname = get-vbrjob -name $selection #Add VM in VBRjob Hyper-V IF($VBRServerType -match "HvServer"){ $newvm = Find-VBRHvEntity -name $vmname IF(!$newvm){ Write-host "No vm found with the name: $vmname" -foreground "red" Return } Add-VBRHvJobObject -Job $jobname -Entities $newvm } #Add VM in VBRjob VMWare ELSEIF($VBRServerType -match "ESX"){ $newvm = Find-VBRViEntity -name $vmname IF(!$newvm){ Write-host "No vm found with the name: $vmname" -foreground "red" Return } Add-VBRViJobObject -Job $jobname -Entities $newvm } ELSE{ Write-host "VBRServerType $VBRServerType not recognized" -Foreground "red" Return } #Get Job object $jobobject = $jobname | Get-VBRJobObject | where{$_.name -match $newvm.name} IF($Application -match "y" -and $indexing -match "y"){ $vssjoboptions = Get-VBRJobVssOptions -job $jobname.name IF($vssjoboptions.enabled -match "false"){ $vssjoboptions.enabled = $true Set-VBRJobVssOptions -Options $vssjoboptions -Job $jobname $jobobjects = Get-VBRJobObject -Job $jobname Foreach($obj in $jobobjects){ $vssobjoptions = Get-VBRJobObjectVssOptions -ObjectInJob $obj $vssobjoptions.enabled = $false set-vbrjobobjectvssoptions -Options $vssobjoptions -object $obj } } IF($vssjoboptions.GuestFSIndexingType -match "none"){ $vssjoboptions.GuestFSIndexingType = "ExceptSpecifiedFolders" Set-VBRJobVssOptions -Options $vssjoboptions -Job $jobname $jobobjects1 = Get-VBRJobObject -Job $jobname Foreach($obj1 in $jobobjects1){ $vssobjoptions = Get-VBRJobObjectVssOptions -ObjectInJob $obj1 $vssobjoptions.GuestFSIndexingType = "None" set-vbrjobobjectvssoptions -Options $vssobjoptions -object $obj1 } } $vssobjectoptions = Get-VBRJobObjectVssOptions -ObjectInJob $jobobject $vssobjectoptions.enabled = $true $vssobjectoptions.IgnoreErrors = $true $vssobjectoptions.SqlBackupOptions.TransactionLogsProcessing = "TruncateonlyonSuccessJob" $vssobjectoptions.ExchangeBackupOptions.TransactionLogsProcessing = "TruncateonlyonSuccessJob" $vssobjectoptions.GuestFSIndexingType = "ExceptSpecifiedFolders" $vssobjectoptions.ExcludedIndexingFolders = $Excludedfolders set-vbrjobobjectvssoptions -Options $vssobjectoptions -object $jobobject } IF($Application -match "y" -and $indexing -match "n"){ $vssjoboptions = Get-VBRJobVssOptions -job $jobname.name IF($vssjoboptions.enabled -match "false"){ $vssjoboptions.enabled = $true Set-VBRJobVssOptions -Options $vssjoboptions -Job $jobname $jobobjects = Get-VBRJobObject -Job $jobname Foreach($obj in $jobobjects){ $vssobjoptions = Get-VBRJobObjectVssOptions -ObjectInJob $obj $vssobjoptions.enabled = $false set-vbrjobobjectvssoptions -Options $vssobjoptions -object $obj } } $vssobjectoptions = Get-VBRJobObjectVssOptions -ObjectInJob $jobobject $vssobjectoptions.enabled = $true $vssobjectoptions.GuestFSIndexingType = "none" $vssobjectoptions.IgnoreErrors = $true $vssobjectoptions.SqlBackupOptions.TransactionLogsProcessing = "TruncateonlyonSuccessJob" $vssobjectoptions.ExchangeBackupOptions.TransactionLogsProcessing = "TruncateonlyonSuccessJob" Set-vbrjobobjectvssoptions -Options $vssobjectoptions -object $jobobject } IF($Application -match "n" -and $indexing -match "y"){ $vssjoboptions = Get-VBRJobVssOptions -job $jobname.name IF($vssjoboptions.GuestFSIndexingType -match "none"){ $vssjoboptions.GuestFSIndexingType = "ExceptSpecifiedFolders" Set-VBRJobVssOptions -Options $vssjoboptions -Job $jobname $jobobjects1 = Get-VBRJobObject -Job $jobname Foreach($obj1 in $jobobjects1){ $vssobjoptions = Get-VBRJobObjectVssOptions -ObjectInJob $obj1 $vssobjoptions.GuestFSIndexingType = "None" set-vbrjobobjectvssoptions -Options $vssobjoptions -object $obj1 } } $vssobjectoptions = Get-VBRJobObjectVssOptions -ObjectInJob $jobobject $vssobjectoptions.GuestFSIndexingType = "ExceptSpecifiedFolders" $vssobjectoptions.Enabled = $false $vssobjectoptions.ExcludedIndexingFolders = $Excludedfolders Set-vbrjobobjectvssoptions -Options $vssobjectoptions -object $jobobject } IF($Application -match "n" -and $indexing -match "n"){ $vssobjectoptions = Get-VBRJobObjectVssOptions -ObjectInJob $jobobject $vssobjectoptions.GuestFSIndexingType = "none" $vssobjectoptions.Enabled = $false set-vbrjobobjectvssoptions -Options $vssobjectoptions -object $jobobject } IF($Application -match "y" -and $indexing -match "y"){ $vssjoboptions = Get-VBRJobVssOptions -job $jobname.name IF($vssjoboptions.enabled -match "false"){ $vssjoboptions.enabled = $true Set-VBRJobVssOptions -Options $vssjoboptions -Job $jobname $jobobjects = Get-VBRJobObject -Job $jobname Foreach($obj in $jobobjects){ $vssobjoptions = Get-VBRJobObjectVssOptions -ObjectInJob $obj $vssobjoptions.enabled = $false set-vbrjobobjectvssoptions -Options $vssobjoptions -object $obj } } IF($vssjoboptions.GuestFSIndexingType -match "none"){ $vssjoboptions.GuestFSIndexingType = "ExceptSpecifiedFolders" Set-VBRJobVssOptions -Options $vssjoboptions -Job $jobname $jobobjects1 = Get-VBRJobObject -Job $jobname Foreach($obj1 in $jobobjects1){ $vssobjoptions = Get-VBRJobObjectVssOptions -ObjectInJob $obj1 $vssobjoptions.GuestFSIndexingType = "None" set-vbrjobobjectvssoptions -Options $vssobjoptions -object $obj1 } } $vssobjectoptions = Get-VBRJobObjectVssOptions -ObjectInJob $jobobject $vssobjectoptions.enabled = $true $vssobjectoptions.IgnoreErrors = $true $vssobjectoptions.SqlBackupOptions.TransactionLogsProcessing = "TruncateonlyonSuccessJob" $vssobjectoptions.ExchangeBackupOptions.TransactionLogsProcessing = "TruncateonlyonSuccessJob" $vssobjectoptions.GuestFSIndexingType = "ExceptSpecifiedFolders" $vssobjectoptions.ExcludedIndexingFolders = $Excludedfolders set-vbrjobobjectvssoptions -Options $vssobjectoptions -object $jobobject } IF($Application -match "y" -and $indexing -match "n"){ $vssjoboptions = Get-VBRJobVssOptions -job $jobname.name IF($vssjoboptions.enabled -match "false"){ $vssjoboptions.enabled = $true Set-VBRJobVssOptions -Options $vssjoboptions -Job $jobname $jobobjects = Get-VBRJobObject -Job $jobname Foreach($obj in $jobobjects){ $vssobjoptions = Get-VBRJobObjectVssOptions -ObjectInJob $obj $vssobjoptions.enabled = $false set-vbrjobobjectvssoptions -Options $vssobjoptions -object $obj } } $vssobjectoptions = Get-VBRJobObjectVssOptions -ObjectInJob $jobobject $vssobjectoptions.enabled = $true $vssobjectoptions.GuestFSIndexingType = "none" $vssobjectoptions.IgnoreErrors = $true $vssobjectoptions.SqlBackupOptions.TransactionLogsProcessing = "TruncateonlyonSuccessJob" $vssobjectoptions.ExchangeBackupOptions.TransactionLogsProcessing = "TruncateonlyonSuccessJob" Set-vbrjobobjectvssoptions -Options $vssobjectoptions -object $jobobject } IF($Application -match "n" -and $indexing -match "y"){ $vssjoboptions = Get-VBRJobVssOptions -job $jobname.name IF($vssjoboptions.GuestFSIndexingType -match "none"){ $vssjoboptions.GuestFSIndexingType = "ExceptSpecifiedFolders" Set-VBRJobVssOptions -Options $vssjoboptions -Job $jobname $jobobjects1 = Get-VBRJobObject -Job $jobname Foreach($obj1 in $jobobjects1){ $vssobjoptions = Get-VBRJobObjectVssOptions -ObjectInJob $obj1 $vssobjoptions.GuestFSIndexingType = "None" set-vbrjobobjectvssoptions -Options $vssobjoptions -object $obj1 } } $vssobjectoptions = Get-VBRJobObjectVssOptions -ObjectInJob $jobobject $vssobjectoptions.GuestFSIndexingType = "ExceptSpecifiedFolders" $vssobjectoptions.Enabled = $false $vssobjectoptions.ExcludedIndexingFolders = $Excludedfolders Set-vbrjobobjectvssoptions -Options $vssobjectoptions -object $jobobject } IF($Application -match "n" -and $indexing -match "n"){ $vssobjectoptions = Get-VBRJobObjectVssOptions -ObjectInJob $jobobject $vssobjectoptions.GuestFSIndexingType = "none" $vssobjectoptions.Enabled = $false set-vbrjobobjectvssoptions -Options $vssobjectoptions -object $jobobject } } } |