Hello everybody
We are having the issue that our backup software sometimes forgets to unlock VMs after it is done with its thing.
The software itself only allows the unlocking by browsing the backup selection and selecting each and every VM individually and hitting "unlock".
This not only hampers new backup attempt sometimes, it also blocks DRS vMotions and manual ones. While troubleshooting this on PS, I noticed that PS was aware that the VM was actually locked by the backup plugin.
So my hope is to find all VMs with such a lock and remove the lock via PS.
Does anybody have experience with this issue or can anyone be of assistance in finding a way to do this?
Thanks in advance for your time
Regards,
Marco
Does the following detect the VMs?
Get-VM | Select Name,
@{N='(s)vMotion Disabled';E={
$vm = $_
($motion | %{
$vm.ExtensionData.DisabledMethod -contains $_
}) -contains $true}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Marco,
Do you have some more info on how those locks are visible (with PowerCLI)?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Basically we need to find out which VMs have the move method disabled by BKB_PLUGIN... and then undo that.
Does the following detect the VMs?
Get-VM | Select Name,
@{N='(s)vMotion Disabled';E={
$vm = $_
($motion | %{
$vm.ExtensionData.DisabledMethod -contains $_
}) -contains $true}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Geez you're good!
Indeed it does!
Combined with this script:
vghetto-scripts/enable-disable-vsphere-api-method.ps1 at master · lamw/vghetto-scripts · GitHub https://github.com/lamw/vghetto-scripts/blob/master/powershell/enable-disable-vsphere-api-method.ps1
I believe I will be able to solve my issue.
Thanks once again!
If you want to remove the lock following one the methods described in KB2008957, you could do the following.
Note that this requires the VM to be powered off.
foreach($vm in Get-VM | where{
$tVM = $_
($motion | %{$tVM.ExtensionData.DisabledMethod -contains $_}) -contains $true}){
$vmxFile = $vm.ExtensionData.LayoutEx.File | where{$_.Type -eq 'config'}
if($vmxFile -and $vm.PowerState -eq 'PoweredOff'){
Remove-VM -VM $vm -Confirm:$false
New-VM -VMFilePath $vmxFile.Name -VMHost $vm.VMHost
}
}
There is another method, without the poweroff requirement, but it is a bit more complex.
See William's How to easily disable vMotion & Cross vCenter vMotion for a particular Virtual Machine?
Since the DisableMethods method is not public, William uses the MOB to call the method.
See his enable-disable-vsphere-api-method.ps1 script.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Saw too late that you already found William's script :smileygrin:
In any case,m you have the alternative from the KB as well now
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you
In case anybody in the future should need something similar:
I changed LucDs search to one using get-view:
$vms = get-view -viewtype VirtualMachine -filter @{"Config.Template"="False";"DisabledMethod"="RelocateVM_Task"}
And then simply ran each item through the Enable-vSphereMethod function:
Enable-vSphereMethod -vc_server $vcenter -vc_username $vcenter_user -vc_password $vcenter_pwd -vmmoref $($_.MoRef.Value) -enable_method $method_name