Skip to content

Instantly share code, notes, and snippets.

@LawrenceHwang
Created January 1, 2016 18:41
Show Gist options
  • Save LawrenceHwang/236e6aadc9112bf50e07 to your computer and use it in GitHub Desktop.
Save LawrenceHwang/236e6aadc9112bf50e07 to your computer and use it in GitHub Desktop.
# Fix the locked changed block tracking file for vms in a VMWare environment.
# It it achieved by flipping the changed block tracking settings.
# Snapshot is used as an alternative so the setting can be changed.
# Requires VMWare PowerCLI 5.1 and PowerShell V3 or above.
#Add the required PowerPLI cmdlets
Add-PSSnapin VMware.VimAutomation.Core
#Parameters
$vCenter="vCenter"
$vm="vm1","vm2","vm3"
#Connect to the vCenter server
Connect-VIServer $vCenter
foreach ($v in $vm){
$vmfix = Get-vm $v | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
#Reconfigure the vm to disable the changed block tracking.
$vmConfigSpec.changeTrackingEnabled = $false
$vmfix.reconfigVM($vmConfigSpec)
$snapshot = New-Snapshot $v -Name "Disable changed block tracking"
$snapshot | Remove-Snapshot -confirm:$false
#Reconfigure the vm to enable the changed block tracking back again.
$vmConfigSpec.changeTrackingEnabled = $true
$vmfix.reconfigVM($vmConfigSpec)
$snapshot = New-Snapshot $v -Name "Enable changed block tracking"
$snapshot | Remove-Snapshot -confirm:$false
}
Disconnect-VIServer $vCenter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment