In this blog I will try to explain how you can delete locked Instant-Clone objects. My colleague Marc already explained how you can do it in the GUI, so if you are not familiar with scripting/PowerShell then this blog is a good alternative.

IMPORTANT: Making changes to the MOB (internal API) is not supported and used at own risk. Not sure what u are doing? contact VMware support!

So how do we start? In my script I made some assumptions like the use of dvSwitches and vlan IDs used in the names of your distributed port groups.
Step 1 is to login to the vCenter and the MOB url.

$mob_url = "https://$vCenter/mob/?moid=AuthorizationManager&method=enableMethods"
$results = Invoke-WebRequest -Uri $mob_url -SessionVariable vmware -Credential $credential -Method GET
Connect-VIServer $vCenter -Credential $credential

Step 2 is to get de MoRef IDs from the VMs in your vlan.

$dvswitch = 'dvs-production'
$vlanId = ''
$vlan = (Get-VDPortgroup -VDSwitch $dvSwitch).where{$_.name -match $vlanId}
$VMs = $vlan.extensionData.vm.value

Step 3 is to build the body to execute the API call for each VM.

$EnableMethod = 'Destroy_Task'
$null = $results -match 'name="vmware-session-nonce" type="hidden" value="?([^\s^"]+)"'
$sessionnonce = $matches[1]
$body = @"
vmware-session-nonce=$sessionnonce&entity=%3Centity+type%3D%22ManagedEntity%22+xsi%3Atype%3D%22ManagedObjectReference%22%3E$vm%3C%2Fentity%3E%0D%0A&method=%3Cmethod%3E$EnableMethod%3C%2Fmethod%3E
"@
# Second request using a POST and specifying our session from initial login + body request
$results = Invoke-WebRequest -Uri $mob_url -WebSession $vmware -Method POST -Body $body

The result is that for a cp-template, cp-replica or cp-parent the option “delete form disk” becomes available in vCenter.
So now you can delete the linked-clone leftovers.

The full PowerShell script (function) can be found here: https://github.com/Sader82/DaaS/blob/master/Enable-VMMethods.ps1

Source: https://www.virtuallyghetto.com/2016/07/how-to-easily-disable-vmotion-cross-vcenter-vmotion-for-a-particular-virtual-machine.html

 8,477 total views,  9 views today