PowerCLI enable CBT on VM’s where CBT is disabled
Problem: Some VM’s have CBT disabled.
Warning: Maybe CBT should not be enabled in your environment. There are pre-requisites and if unpatched hosts, potential bugs with CBT. Please be diligent in researching CBT (Change Block Tracking) first.
Solution: (note: bypasses any VM's with existing snapshots)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$vcenter="vcenter.domain.tld" | |
Import-Module -Global VMware.VimAutomation.Core | |
Disconnect-VIServer * -Confirm:$false -Force | Out-Null #Disconnect all previously connected vcenter servers | |
# new spec | |
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec | |
# enable ctk | |
$vmConfigSpec.changeTrackingEnabled = $true | |
clear | |
connect-viserver $vcenter | |
write-host | |
$targets = Get-VM | where {-not $_.ExtensionData.Snapshot} | Where-Object {$_.ExtensionData.Config.ChangeTrackingEnabled -eq $false} | |
if ($targets) { | |
ForEach ($target in $targets) { | |
$vm = $target.Name | |
$vmview=get-vm $target | Get-View | |
write-host "enabling CBT for $vm" | |
$vmview.reconfigVM($vmConfigSpec) | |
$snap=New-Snapshot $vm -Name "Enable CBT" | |
$snap | Remove-Snapshot -confirm:$false | |
} | |
} else { write-host "nothing to do." } | |
Disconnect-VIServer $vcenter -Confirm:$false -Force |
~~~
As always, good luck.
Please consider crypto tipping: