Home Datacenter Enabling Change Block Tracking (CBT) with PowerCLI Script

Enabling Change Block Tracking (CBT) with PowerCLI Script

by Philip Sellers

Change Block Tracking (CBT) is a technology in VMware used to record all the changed data within a VMDK file so that when backup software runs incremental backups, it knows exactly what has changed and can send only differences to the backup software.  This is a technology that greatly improves backup speed and efficiency by only moving changed data.  With many backup software moving to an incremental forever  process, change block tracking is an enabling technology for the backup.

Most software can enable CBT on an individual VM, however, if you are in the beginning phases of implementing a new backup software or virtual deployment, you may want to proactively enable CBT across the entire farm.  There may also be instances where a few of your VMs have CBT disabled and you need to enable it for just those VMs.  I developed a script I used myself to enable CBT across an entire vCenter instance, which checks for VMs with CBT disabled and then goes through the process of reconfiguring the VM, taking a snapshot and removing the snapshot to enable CBT on the VM.

The script is below.  Please be warned – as written – this script removes any existing snapshots on the VMs with CBT disabled.

[ps]$targets = Get-VM | Select Name, @{N="CBT";E={(Get-View $_).Config.ChangeTrackingEnabled}} | WHERE {$_.CBT -like "False"}
ForEach ($target in $targets) {
$vm = $target.Name
Get-VM $vm | Get-Snapshot | Remove-Snapshot -confirm:$false
$vmView = Get-vm $vm | get-view
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.changeTrackingEnabled = $true
New-Snapshot -VM (Get-VM $vm ) -Name "CBTSnap"
Get-VM $vm | Get-Snapshot -Name "CBTSnap" | Remove-Snapshot -confirm:$false

You may also like