9 Replies Latest reply on May 31, 2017 9:24 AM 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

          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

              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

                  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?

                    • 7. Re: Get Protection Group of a VM
                      piercj2 Enthusiast

                      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

                      • 8. Re: Get Protection Group of a VM
                        meda1983 Enthusiast

                        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

                        • 9. Re: Get Protection Group of a VM
                          TheVMinator Master

                          ok thanks all for the input