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