VMware Cloud Community
winsolo
Enthusiast
Enthusiast
Jump to solution

Unprotect a VM using UnprotectVms(VMware.Vim.ManagedObjectReference[] vms) Method

Is there a way to call these methods to unprotect and unassociate a particular VM from a protection group?

Snag_190f13c4.png

I was looking at one of the old blogs about it in PowerCLI 5.5 R2 and the Site Recovery Manager API - VMware vSphere Blog and wasn't able to construct a way to unprotect VM from a group, although I was just able to get all the VMs with their protection groups associated with.

$SrmConnection=Connect-SrmServer

$SrmApi = $SrmConnection.ExtensionData

$ProtectionGroups = $SrmApi.Protection.ListProtectionGroups()

foreach($PG in $ProtectionGroups) {

    $PG.ListProtectedVMs() | Select @{N='ProtectionGroup';E={($PG.GetInfo().Name)}},VmName,State,PeerState

}

Snag_1913ea1b.png

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Using the protectiongroup you have in $pg, can't you do.

$vm = Get-VM -Name MyVM

$pg.UnprotectVms($vm.ExtensionData.MoRef)

Or if you want to unprotected all VMs in a group

$pg.ListProtectedVms() |

ForEach-Object -Process {

    $pg.UnprotectVms($_.vm.MoRef)

}

Or alternatively

$protVM = $pg.ListProtectedVms()

$pg.UnprotectVms($protVM.vm.MoRef)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

3 Replies
LucD
Leadership
Leadership
Jump to solution

Using the protectiongroup you have in $pg, can't you do.

$vm = Get-VM -Name MyVM

$pg.UnprotectVms($vm.ExtensionData.MoRef)

Or if you want to unprotected all VMs in a group

$pg.ListProtectedVms() |

ForEach-Object -Process {

    $pg.UnprotectVms($_.vm.MoRef)

}

Or alternatively

$protVM = $pg.ListProtectedVms()

$pg.UnprotectVms($protVM.vm.MoRef)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

winsolo
Enthusiast
Enthusiast
Jump to solution

Even though $PG and $vm do have values, calling the method $pg.UnprotectVms($vm.ExtensionData.MoRef) doesn't work.

Snag_1959e787.png

Reply
0 Kudos
winsolo
Enthusiast
Enthusiast
Jump to solution

Sorry, I used a wrong value. Instead of using "get-vm TESTVM21" for $vm, I used the value of "$ProtectionGroups[3].ListProtectedVms()"

It works.

Snag_1966bb28.png

Snag_196951ff.png

Reply
0 Kudos