PowerShell script exchange
Post Reply
MOBO
Influencer
Posts: 17
Liked: 5 times
Joined: Jan 24, 2015 7:26 am
Full Name: Morten Boegeskov
Contact:

CBT Reset Script

Post by MOBO »

Hi
i have been working on a script to run thru our vCenter and do CBT reset on all VMs when i upgrade to v9
my single server tests have been successful, so i pretty sure it should work,but i thought i would ask if anyone see major downsides/risks to do it with powerCLI or had the same idea before ?

Code: Select all

Add-PSSnapin VMware.VimAutomation.Core
$VMServer = "vCenter.domain.local"
Connect-VIServer -server $VMServer -User Default-User -Password Default-Password

$vms= Get-VM
foreach ($vm in $vms){ 
$snapshots = Get-Snapshot $vm
if($snapshots -notlike ""){
Write-Output "Remove Snapshot "$snapshots.Name
Get-Snapshot $vm | Remove-Snapshot -confirm:$false
}
$vmtest = Get-vm $vm| get-view
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
#disable ctk
$vmConfigSpec.changeTrackingEnabled = $false
$vmtest.reconfigVM($vmConfigSpec)
Start-Sleep -s 10
$snap=New-Snapshot $vm -Name "Disable CBT"
Start-Sleep -s 10
$snap | Remove-Snapshot -confirm:$false
Write-Output "Disable CBT on"$vm
# enable ctk
$vmConfigSpec.changeTrackingEnabled = $true
$vmtest.reconfigVM($vmConfigSpec)
Start-Sleep -s 10
$snap=New-Snapshot $vm -Name "Enable CBT"
Start-Sleep -s 10
$snap | Remove-Snapshot -confirm:$false
Write-Output "Enable CBT on"$vm
}
Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests