VMware Cloud Community
m_crocker
Enthusiast
Enthusiast

Generate report of VMs not configured for SRM protection

So I have been playing around with PowerCLI's ability to connect to the SRM API and realising I need to understand the API better (and PowerShell)! I have walked through Ken Werneburg's blogs on VMware.com which have been really helpful in getting started. Just having some difficulty retrieving the information that I am seeking and understanding how to provide the correct syntax for these API commands. The goal I am trying to achieve is to generate a report of VMs residing on SRM replicated datastores and are yet to be configured. I would like to run a report that I will then send by email to the  infrastructure team to then review to determine if a) this VM should be configured for protection and added into a recovery plan or b) this VM should not be on the SRM replicated datastore, get the hell outta here!

I have connected to SRM using PowerCLI and created a variable to store all of the protection groups.

$ProtectionGroups = $srmapi.Protection.ListProtectionGroups()

If I do a Get-Member on this variable I can see some of the methods that I want to run in order to start retrieving information.

PS C:\Scripts> $ProtectionGroups | gm

   TypeName: VMware.VimAutomation.Srm.Views.SrmProtectionGroup

Name                    MemberType Definition                                                                                                                                               

----                    ---------- ----------                                                                                                                                               

AssociateVms            Method     void AssociateVms(VMware.Vim.ManagedObjectReference[] vms)                                                                                               

Equals                  Method     bool Equals(System.Object obj)                                                                                                                           

GetHashCode             Method     int GetHashCode()                                                                                                                                        

GetInfo                 Method     VMware.VimAutomation.Srm.Views.SrmProtectionGroupInfo GetInfo()                                                                                          

GetPeer                 Method     VMware.VimAutomation.Srm.Views.SrmProtectionGroupPeer GetPeer()                                                                                          

GetProtectionState      Method     VMware.VimAutomation.Srm.Views.SrmProtectionGroupProtectionState GetProtectionState()                                                                    

GetType                 Method     type GetType()                                                                                                                                           

ListAssociatedVms       Method     System.Collections.Generic.List[VMware.Vim.VirtualMachine] ListAssociatedVms()                                                                           

ListProtectedDatastores Method     System.Collections.Generic.List[VMware.Vim.Datastore] ListProtectedDatastores()                                                                          

ListProtectedVms        Method     System.Collections.Generic.List[VMware.VimAutomation.Srm.Views.SrmProtectionGroupProtectedVm] ListProtectedVms()                                         

ListRecoveryPlans       Method     System.Collections.Generic.List[VMware.VimAutomation.Srm.Views.SrmRecoveryPlan] ListRecoveryPlans()                                                      

ProtectVms              Method     VMware.VimAutomation.Srm.Views.SrmProtectionTask ProtectVms(VMware.VimAutomation.Srm.Views.SrmProtectionGroupVmProtectionSpec[] vms)                     

QueryVmProtection       Method     System.Collections.Generic.List[VMware.VimAutomation.Srm.Views.SrmProtectionGroupVmProtectionInfo] QueryVmProtection(VMware.Vim.ManagedObjectReference[]...

ToString                Method     string ToString()                                                                                                                                        

UnassociateVms          Method     void UnassociateVms(VMware.Vim.ManagedObjectReference[] vms)                                                                                             

UnprotectVms            Method     VMware.VimAutomation.Srm.Views.SrmProtectionTask UnprotectVms(VMware.Vim.ManagedObjectReference[] vms)                                                   

MoRef                   Property   VMware.Vim.ManagedObjectReference MoRef {get;set;}

After reading some of the SRM API guide, I believe I am interested in QueryVmProtection or maybe the ListAssociatedVms as then I might be able to filter out the state. Not sure what "not configured" looks like but I assume it would be a property of an associated VM in a protection group.

Why can I run $ProtectionGroups.ListProtectedVms() successfully but I cannot use the same syntax for ListAssociatedVms() or QueryVmProtection()? Do I need to write the command in a different format? Trying to run this against an object in the array yields no differing results either. e.g. $ProtectionGroups[0].ListAssociatedVms(), etc.

Any help is appreciated!

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership

Reply
0 Kudos
m_crocker
Enthusiast
Enthusiast

Just had a quick read through, seems to still be an open question as well? I would need to rerun the command to see if the response is the same but it sounds familiar. Becoming a little difficult to report on this information given we have gotten so used to PowerCLI and cmdlets doing the task at hand.

Reply
0 Kudos
m_crocker
Enthusiast
Enthusiast

Looks like similar symptoms.

PS C:\Scripts> $protectiongroups[0].ListAssociatedVms()

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

At line:1 char:1

+ $protectiongroups[0].ListAssociatedVms()

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

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

    + FullyQualifiedErrorId : VimException

ListProtectedDatastores()

ListProtectedVms()

ListRecoveryPlans()

All execute without a hitch.

I was wondering (assuming) that I could perform a delta on ListProtectedVms() vs. List AssociatedVms() to determine which VMs are sitting on a protected datastore but are yet to be configured for protection. That's my aim.

Reply
0 Kudos
admin
Immortal
Immortal

The ListAssociatedVms is just for vSphere Replication, it isn't valid for array based replication (which it sounds like what you are most interested in).

It might be worth doing the following for each array based replication protection group:

a) get the list of protected VMs: ListProtectedVms() then get actual VM objects

b) get the list of protected datastores: ListProtectedDatastores() then get actual datstore objects

c) get the list of VMs on those protected datastores: Get-VM -Datastore X

d) return the VMs in results of (c) but not in results of (a)

m_crocker
Enthusiast
Enthusiast

Thanks for the guidance. Unfortunately my PowerShell skills are lacking and might have to park this. Spent too much time trying to figure this out. I might rely on SRM alarms to raise alerts when there are unprotected VMs sitting on our SRM replicated datastores. Hopefully in the future there will be cmdlets to make this easier.

Reply
0 Kudos
admin
Immortal
Immortal

Sorry for the late response but VMworld occupied all my time the last few weeks. I have added a function to identify associated but unprotected VMs in my set of example scripts here -> SRM-Cmdlets/SrmFunctions.ps1

It seems to work for vSphere Replication and I think it "may" work for ABR as well though I am not able to test it as my lab doesn't have ABR configured at the moment.

Reply
0 Kudos