Search This Blog

Wednesday, May 15, 2024

Powershell Global VM Exclusion

#Scenario 3: Global VM Exclusion

#Test case 1: testvm_* -passed

#test case 2: vm_* -passed

#Test case 3: vm* - failed error -unsupported entity

#Test case 4: *vm* - failed error - unsupported entity

#Test case 5: vm (no pattern)- passed. No vm excluded as cannot find vm. no error

Connect-VBRServer -Server "VBR121RTM"

$vmToExclude = Find-VBRViEntity -VMsAndTemplates -Name "*vm*" | Where-Object {$_.Type -eq "Vm"}

foreach ($vm in $vmToExclude)

{

    Add-VBRVMExclusion -Entity $vmToExclude

}

#Verify the global vm exclusion

Get-VBRVMExclusion

Disconnect-VBRServer

}






Exclude VM By Pattern for a Job with Selecting Host

 #Scenario 2: Exclude vm by the pattern for a job with the predefined host (entire vm on host)

#Error - will not work as no VM object on the backup job. Only Host with no vm


Connect-VBRServer -Server "VBR121RTM"

# Specify the name of the backup job and the name of the VM to exclude

$backupJobName = "Entire VM Backup Job By Host"

# Specify the vm extension to exclude

$vmNameToExclude = Get-VBRJobObject -Job $backupJobName -Name "*vm*"

Remove-VBRJobObject -Objects $vmNameToExclude

# Get the backup job object

$backupJob = Get-VBRJob -Name $backupJobName

#Save the backup Job

Set-VBRJobOptions -Job $backupJob

Disconnect-VBRServer


Exclude VM By Pattern for Job With Predefined Object

 #Scenario 1: Exclude vm by the pattern for a job with predefined object


Connect-VBRServer -Server "VBR121RTM"

# Specify the name of the backup job and the name of the VM to exclude

$backupJobName = "Scenario 1: Ransomware Scenario"

# Specify the vm extension to exclude

$vmNameToExclude = Get-VBRJobObject -Job $backupJobName -Name "*vm*"

#test case 1 - vm*

#test case 2 - *vm

#test case 3 - *vm*

Remove-VBRJobObject -Objects $vmNameToExclude

# Get the backup job object

$backupJob = Get-VBRJob -Name $backupJobName

#Save the backup Job

Set-VBRJobOptions -Job $backupJob

Disconnect-VBRServer