Issue: You need to enable Change Block Tracking (CBT) on numerous virtual machines and have it take effect immediately.
Background: Enabling change block tracking does not take effect immediately and requires a suspend/resume or snapshot create/delete. This process of changing the CBT setting and activating the change becomes incredibly time consuming.
Solution: Enable Change Block Tracking via PowerCLI Script
- Copy the below txt and paste into a text file with extension .ps1. Place this file in an easy to browse to location for example c:\CBT-SCRIPT
# remember to connect to VCenter server: Connect-VIServer -Server vcenter01 #show current change block tracking status Get-VM | Get-View | Sort Name | Select Name, @{N="ChangeTrackingStatus";E={$_.Config.ChangeTrackingEnabled}} $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 $vmView.reconfigVM($vmConfigSpec) New-Snapshot -VM (Get-VM $vm ) -Name "CBTSnap" Get-VM $vm | Get-Snapshot -Name "CBTSnap" | Remove-Snapshot -confirm:$false } #show change block tracking status again Get-VM | Get-View | Sort Name | Select Name, @{N="ChangeTrackingStatus";E={$_.Config.ChangeTrackingEnabled}}
Note: I make no warranties and take no responsibility for your use of scripts. Use your judgement and expertise to review the scripted command and determine the applicability and ramifications in your environment.
- Launch VMWare PowerCLI on your VCenter Server
- Browse to the folder with the script
- Use the following command to connect to VCenter
Connect-VIServer -Server <VCENTERSERVERNAME>
Will it reboot the VM or suppress the reboot?
I don’t see any code in the scripts that would initiate a reboot. This script opts to create and remove a snapshot in order to make the change active so a reboot is not necessary.
how the heck did you know my vcenter’s hostname?? –joke
long time reader here, thanks for sharing