Skip to content

Instantly share code, notes, and snippets.

@meoso
Created January 29, 2020 14:18
Show Gist options
  • Save meoso/d97c9400a0dad69bab191c2e036cfbec to your computer and use it in GitHub Desktop.
Save meoso/d97c9400a0dad69bab191c2e036cfbec to your computer and use it in GitHub Desktop.
PowerCLI enable CBT on VM's where CBT is disabled
$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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment