VMware Cloud Community
TheVMinator
Expert
Expert
Jump to solution

Get Protection Group of a VM

With the SRM PowerCLi cmdlets, I see it is possible to get a list of all VMs in a protection group.  But if I just have the name of one VM, how can I query SRM and find out the protection group it is in?  Is this possible?

Thanks!

Reply
0 Kudos
1 Solution

Accepted Solutions
meda1983
Enthusiast
Enthusiast
Jump to solution

Code given by Lucd works. it just needs a little tweak to update the metadata.  once you run the below function, it updates the values so you can see the protection group details.

$protectedVms = $protectionGroup.ListProtectedVms()

$protectedVms | % { $_.Vm.UpdateViewData() }

here is some of the scripts i created to replace SRM tool with powershell.  one of the scripts in there has this function and can be used to export all the data from SRM to a csv which later can be used to recover all the virtual machines without SRM.

https://www.linkedin.com/pulse/powershell-scripts-recover-mission-critical-you-do-have-vamshi-meda

View solution in original post

Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

Afaik there is no such method, but you can of course scan all groups for that VM.

Something like this

$vmName = 'MyVM'

$srm = Connect-SrmServer -RemoteCredential $cred

foreach($group in $srm.ExtensionData.Protection.ListProtectionGroups()){

    Get-VM -id $($group.ListAssociatedVMs().MoRef) |

    where{$_.Name -eq $vmName} |

    Select @{N='Group';E={$group.Name}},@{N='VM';E={$_.Name}}

}


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

TheVMinator
Expert
Expert
Jump to solution

ok great - thanks again.  My script errored out though - any ideas? 

Exception calling "ListAssociatedVms" with "0" argument(s): "The operation is not supported on the object."

At line:5 char:18

+     Get-VM -id $($group.ListAssociatedVMs().MoRef) |

+                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : VimException

Get-VM : Cannot validate argument on parameter 'Id'. The argument is null or empty. Provide an argument that is

not null or empty, and then try the command again.

At line:5 char:16

+     Get-VM -id $($group.ListAssociatedVMs().MoRef) |

+                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Get-VM], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Do you happen to have empty protection groups?


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

TheVMinator
Expert
Expert
Jump to solution

Not sure -there might be - but most are filled, and I'm getting this set of error messages 50 times or so in repetition with no successful output of data even for the protection group I know this VM happens to be in.

Any other ideas?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

$vmName = 'MyVM'

$srm = Connect-SrmServer -RemoteCredential $cred

foreach($group in $srm.ExtensionData.Protection.ListProtectionGroups()){

    Get-VM -id $($group.ListProtectedVMs().VM.MoRef) |

    where{$_.Name -eq $vmName} |

    Select @{N='Group';E={$group.Name}},@{N='VM';E={$_.Name}}

}


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

TheVMinator
Expert
Expert
Jump to solution

It still fails - I attached the output.  If you look at the file - note one strange line near the bottom where it shows this:

Group                                                     VM                                                     

-----                                                          --                                                     

                                                          LAXPROD234 

Any ideas?

Reply
0 Kudos
piercj2
Enthusiast
Enthusiast
Jump to solution

Is there any way to suppress the warning output in the PowerShell ISE for all the Protection Groups that do not contain the VM Name ?

I've tried  ErrorAction and Warning Action but the Red Text is displayed in the ISE for all Protection Groups that don't contain a particular VM.

Perhaps something like try/catch ?

$srm = Connect-SrmServer -Credential $cred
$vmName = 'MyVM'

foreach($group in $srm.ExtensionData.Protection.ListProtectionGroups()){
Try {
    Get-VM -id $($group.ListProtectedVMs().VM.MoRef) |
    where{$_.Name -eq $vmName} |
    Select @{N='Group';E={$group.Name}},@{N='VM';E={$_.Name}}
    }

Catch {
      * > $null
      }

}

Thanks

Reply
0 Kudos
meda1983
Enthusiast
Enthusiast
Jump to solution

Code given by Lucd works. it just needs a little tweak to update the metadata.  once you run the below function, it updates the values so you can see the protection group details.

$protectedVms = $protectionGroup.ListProtectedVms()

$protectedVms | % { $_.Vm.UpdateViewData() }

here is some of the scripts i created to replace SRM tool with powershell.  one of the scripts in there has this function and can be used to export all the data from SRM to a csv which later can be used to recover all the virtual machines without SRM.

https://www.linkedin.com/pulse/powershell-scripts-recover-mission-critical-you-do-have-vamshi-meda

Reply
0 Kudos
TheVMinator
Expert
Expert
Jump to solution

ok thanks all for the input

Reply
0 Kudos