VM CTK Cleanup Script

Post date: Jun 12, 2015 5:31:58 PM

Sometimes CTK files are corrupt preventing a VM from powering on. The below script will rename the CTK files if the VM's path on the datastore is the same as its name and the VMDKs are kept together.

# ================================================================================

# ======== Clean up VM CTK files ========

# ======== by ========

# ======== KnightUSN ========

# ======== v1.0 - 6/12/2015 ========

# ================================================================================

# Run .\SET-VMctkCleanUp.ps1 "VM Name"

# This script looks for the VMstores location and renames items containing "ctk" to .old

param(

[parameter(Mandatory = $true)]

[string[]]$param

)

$VM = Get-VM $param

$DSP = Get-Datastore -id $VM.DatastoreIdList

$vDSP = $DSP.DatastoreBrowserPath + "\" + $VM.name

Get-ChildItem $vDSP | ?{$_.name.contains("ctk")} | foreach{

$NewN = $_.name + ".old"

$fullDSP = $vDSP + "\" + $_.name

Get-Item $fullDSP | Rename-Item -NewName $NewN

}

$VM.ExtensionData.ConsolidateVMDisks()