6 Replies Latest reply on Apr 21, 2017 8:45 PM by TheVMinator

    Get Protection Group of a VM

    TheVMinator Master

      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!

        • 1. Re: Get Protection Group of a VM
          LucD Guru Community Warrior User Moderators vExpert

          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}}

          }

          1 person found this helpful
          • 2. Re: Get Protection Group of a VM
            TheVMinator Master

            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

            • 3. Re: Get Protection Group of a VM
              LucD Guru Community Warrior User Moderators vExpert

              Do you happen to have empty protection groups?

              1 person found this helpful
              • 4. Re: Get Protection Group of a VM
                TheVMinator Master

                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?

                • 5. Re: Get Protection Group of a VM
                  LucD Guru Community Warrior User Moderators vExpert

                  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}}

                  }

                  1 person found this helpful
                  • 6. Re: Get Protection Group of a VM
                    TheVMinator Master

                    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?