VMware Cloud Community
1MarkM
Enthusiast
Enthusiast
Jump to solution

SRM Reports using the API

Folks:

I'll admit I am not a powercli guru, and utilize other people's published code to get the job done. In this case, it's a result in trying to find a "canned" report that would dump the VM/Protection Group/Recovery plan into a report that can be added to our audited DR plan. For the life of me I don't understand why this isn't already in the product, but that be as it may. The below code works but I happen to have two recovery "realms" - I protect our HQ Cluster/Vcenter1 with a recovery plan in our Colo Cluster/Vcenter2, and vice versa I protect our Colo Cluster/Vcenter2 with a recovery plan in HQ Cluster/Vcenter1. Vcenters in in embedded link mode, SRM 8.2 Vcenter 6.7U3.

The crux of the problem is "$srmApi.Protection.ListProtectionGroups" list all of the protection groups (both HQ and Colo) which is good, but "$protectionGroup.ListAssociatedVms()" only sees VM's in my HQ Vcenter. The Colo VM's  error out-

Exception calling "UpdateViewData" with "0" argument(s): "The object 'vim.VirtualMachine:vm-355' has already been deleted or has not been completely created"

At C:\Temp\srm_report.ps1:13 char:16

+     $vms | % { $_.UpdateViewData() }

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

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

    + FullyQualifiedErrorId : VimException

I played with the connect statement to use the Colo Vcenter as the connection point, but same result, the Colo VM's are not detected. This was not what I was expecting I figured I'd be missing the HQ VM's.

$credential = Get-Credential

Connect-VIServer -Server 10.10.10.10 -Credential $credential

Connect-SrmServer -port 443 -Credential $credential -RemoteCredential $credential

So I'm at a loss to explain how to get the "$protectionGroup.ListAssociatedVms()" to reference both Vcenters. What do you think?

srmApi = $srmConnection.ExtensionData

$protectionGroups = $srmApi.Protection.ListProtectionGroups()

#Generate a report of the virtual machines associated with all protection groups.

$protectionGroups | % {

    $protectionGroup = $_

   

    $protectionGroupInfo = $protectionGroup.GetInfo()

   

    # The following command lists the virtual machines associated with a protection group

    $vms = $protectionGroup.ListAssociatedVms()

    # The result of the above call is an array of references to the virtual machines at the vSphere API

    # To populate the data from the vSphere connection, call the UpdateViewData method on each virtual machine view object

    $vms | % { $_.UpdateViewData() }

    # After the data is populated, use it to generate a report

    $vms | %{

        $output = "" | select VmName, PgName

        $output.VmName = $_.Name

        $output.PgName = $protectionGroupInfo.Name

        $output

    }

} | Format-Table @{Label="VM Name"; Expression={$_.VmName} }, @{Label="Protection group name"; Expression={$_.PgName} }

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

When you tried both vCenters with the Connect-VIServer cmdlet, did you also switch the SrmServerAddress value on the Connect-SrmServer cmdlet.

Some SRM API methods only work on one site (protected vs protecting), others on both.

Unfortunately, I don't have something similar in my lab, so I can't really try it out.


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

View solution in original post

Reply
0 Kudos
6 Replies
scott28tt
VMware Employee
VMware Employee
Jump to solution

Moderator: I couldn't decide whether to move this thread to the SRM area or the PowerCLI area, but chose PowerCLI.


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

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

When you tried both vCenters with the Connect-VIServer cmdlet, did you also switch the SrmServerAddress value on the Connect-SrmServer cmdlet.

Some SRM API methods only work on one site (protected vs protecting), others on both.

Unfortunately, I don't have something similar in my lab, so I can't really try it out.


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

Reply
0 Kudos
1MarkM
Enthusiast
Enthusiast
Jump to solution

Tried your advice -srmserveraddress/colo Vcenter connection, it sounded promising, but I still have same results, just my HQ VM's are defined, which surprises me.

I do see the connection to my Colo Vcenter (172.16.124.112 ) and Colo SRM (172.16.124.111)

PS C:\temp> C:\Temp\VM-Connect-with SRM.ps1

cmdlet Get-Credential at command pipeline position 1

Supply values for the following parameters:

Name                           Port  User                         

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

172.16.124.112                 443   DOMAIN\user             

ServiceUri    : https://172.16.124.111/vcdr/extapi/sdk

SessionSecret : "6d560a3f47fd3f27119218b3223853bf5be3fd9d"

User          : user

IsConnected   : True

Port          : 443

Version       : 8.2.0

Build         : 14761908

ProductLine   : srm

InstanceUuid  : 6c072028-e5ee-40d7-b291-4329b6ac5cda

RefCount      : 1

ExtensionData : VMware.VimAutomation.Srm.Views.SrmServiceInstance

Uid           : /SrmServer=user@172.16.124.111:443/

Id            : /SrmServer=user@172.16.124.111:443/

Name          : 172.16.124.111

IsInUse       : True

Reply
0 Kudos
1MarkM
Enthusiast
Enthusiast
Jump to solution

As a FYI, I was able to get the data I needed using the below. Though when connected to HQ SRM, the Colo VM's were not recognized, but when connected to the Colo SRM the reverse (which was good to see). So between the both connections I was able to get each VM and it's protection group. I'm still on the prowl for a better more comprehensive report option... but for now I got what I needed for part of our DR documentation.

Get-SrmProtectionGroup | %{

    $pg = $_

    Get-SrmProtectedVM -ProtectionGroup $pg } | %{

        $output = "" | select VmName, PgName

        $output.VmName = $_.Vm.Name

        $output.PgName = $pg.GetInfo().Name

        $output

    } | Format-Table -AutoSize @{Label="VM Name"; Expression={$_.VmName} },

                     @{Label="Protection group name"; Expression={$_.PgName}

}

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That was what I meant with my previous answer.

Glad you found a working solution.


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

Reply
0 Kudos
1MarkM
Enthusiast
Enthusiast
Jump to solution

Just wanted to add for anyone that bumps into the, and is a novice like me to definitely look into:

benmeadowcroft/SRM-Cmdlets

Reply
0 Kudos