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!