Ask the Community
Groups
VMware CBT Reset PowerShell Cmdlet - Connect IT Community | Kaseya
<main> <article class="userContent"> <h2 data-id="issue"><strong>ISSUE</strong></h2> <p>Resetting CBT is an ardous task that requires you to power off the VM and edit VM ctkEnabled property using vSphere Client or use VMware APIs to disable/enable CBT and create/remove a temporary snapshot to purge CBT tables.<br><br>We have created a powershell cmdlet that uses VMware PowerCLI to automate this CBT reset operation in one or multiple VMs. As explained the script needs to create/remove a temporary snapshot so it is recommended that you do not run it during production hours on VMs that may be impacted by a VM snapshot.<br> </p> <h2 data-id="running-the-script-and-cmdlets">Running the script and cmdlets</h2> <ul><li>Download <a rel="nofollow" href="/home/leaving?allowTrusted=1&target=https%3A%2F%2Fraw.githubusercontent.com%2FUnitrends%2Funitrends-scripts%2Fmaster%2FUnitrendsCbt.ps1">UnitrendsCBT.ps1</a> script from <a rel="nofollow" href="/home/leaving?allowTrusted=1&target=https%3A%2F%2Fgithub.com%2FUnitrends%2Funitrends-scripts">Unitrends GitHub repo</a>.</li> <li>Open PowerCLI (32-bit) console. If you use default PowerCLI console you may get error “Operation is not valid due to the current state of the object” while running CBT-Reset.</li> <li>CD to Path where you downloaded UnitrendsCBT.ps1 script. <pre class="code codeBlock" spellcheck="false" tabindex="0"> PowerCLI C:\> cd C:\Unitrends\scripts\CBT</pre> </li> <li>Allow Execution of unsigned powershell script. (Set-ExecutionPolicy Bypass) <pre class="code codeBlock" spellcheck="false" tabindex="0"> PowerCLI C:\Unitrends\scripts\CBT> Set-ExecutionPolicy Bypass</pre> </li> <li>Load Cmdlets from UnitrendsCBT.ps1 running command. <pre class="code codeBlock" spellcheck="false" tabindex="0"> PowerCLI C:\Unitrends\scripts\CBT> . .\UnitrendsCBT.ps1</pre> </li> <li>Connect to VMware server using PowerCLI Connect-VIServer. <pre class="code codeBlock" spellcheck="false" tabindex="0"> PowerCLI C:\Unitrends\scripts\CBT> Connect-VIServer -Server <vsphere server> -User <username> -Password <password></pre> </li> <li>Reset-CBT on one or multiple VMS. <pre class="code codeBlock" spellcheck="false" tabindex="0"> PowerCLI C:\Unitrends\scripts\CBT> Get-VM test01|Reset-CBT</pre> </li> </ul> <h2 data-id="sample-usage-and-output">Sample Usage and Output</h2> <code class="code codeInline" spellcheck="false" tabindex="0"> </code> <pre class="code codeBlock" spellcheck="false" tabindex="0"> PowerCLI C:\Unitrends\scripts\CBT> Set-ExecutionPolicy Bypass PowerCLI C:\Unitrends\scripts\CBT> Connect-VIServer -Server vcenter01 -User root -Port password PowerCLI C:\Unitrends\scripts\CBT> . .\UnitrendsCBT.ps1 PowerCLI C:\Unitrends\scripts\CBT> Get-VM test0*|Get-CBT Name PowerState CbtEnabled ---- ---------- ---------- test01 PoweredOn True test02 PoweredOn True PowerCLI C:\Unitrends\unitrends-scripts> Get-VM test0*|Reset-CBT [*] test01 : OK [*] test02 : OK</pre> <br>That is all you need to reset CBT, Get-VM is a PowerCLI command that will get a list of VMs, that list will be passed to our Reset-CBT. So with just command you can reset CBT on a VM, all VMs in a cluster, folder, etc. <h2 data-id="other-cmdlets">Other cmdlets</h2> We have included other cmdlets that are not necessary to reset cbt but you may find useful to check and change CBT status Get-CBT, Get-ChangeId, Enable-CBT, Disable-CBT <pre class="code codeBlock" spellcheck="false" tabindex="0"> PowerCLI C:\Unitrends\scripts\CBT> Get-VM test0*|Disable-CBT [*] test02 : OK Verify CBT Status: PowerCLI C:\Unitrends\scripts\CBT> Get-VM test0*|Get-CBT Name PowerState CbtEnabled ---- ---------- ---------- test01 PoweredOn False test02 PoweredOn False PowerCLI C:\Unitrends\scripts\CBT> Get-VM test0*|Enable-CBT [*] test01 : OK [*] test02 : OK PowerCLI C:\Unitrends\scripts\CBT> Get-VM test0*|Get-CBT Name PowerState CbtEnabled ---- ---------- ---------- test01 PoweredOn True test02 PoweredOn True PowerCLI C:\Unitrends\scripts\CBT> Get-VM test01|Get-ChangeId [*] test01 -> 52 ba 35 cd 98 4e 0c 11-a4 7b f5 02 21 88 4c dd/4 PowerCLI C:\Unitrends\scripts\CBT> get-vm test01|Disable-CBT [*] test01 : OK PowerCLI C:\Unitrends\scripts\CBT> get-vm test01|Get-ChangeId [*] test01 -> CBT is disabled PowerCLI C:\Unitrends\scripts\CBT> get-vm test01|Enable-CBT [*] test01 : OK PowerCLI C:\Unitrends\scripts\CBT> get-vm test01|Get-ChangeId [*] test01 -> 52 62 20 74 d6 82 b1 67-a5 55 69 60 da 9a 79 a2/4</pre> </article> </main>