VMware Cloud Community
rami2aa
Contributor
Contributor

SRM 8.1 PowerCli and API code

I’m using the following Powershell script to get the Recovery setting of a protected VM, but I’m getting the error message in the output following the Powershell code below, can someone please tell me if there is something wrong with the script or the actual protected VM configuration on SRM 8.1.2 version?

Import-Module -Name D:\VMware\Scripts\SRM-Cmdlets-0.2\Meadowcroft.Srm.psd1

$credential = Get-Credential

Connect-VIServer -Server htapll0201.example.com

Connect-SrmServer -Credential $credential -RemoteCredential $credential

$pg = Get-SrmProtectionGroup "PBS pbsrmmuhp401 Prod PG"

$pginfo = $pg.GetInfo()

$pvms = Get-SrmProtectedVM -ProtectionGroup $pg

$rps = Get-SrmRecoveryPlan -ProtectionGroup $pg

$rpnames = $rps | %{ $_.GetInfo().Name }

$pvms | %{

$pvm = $_

Write-Host $pvm.Vm.Name

$rs = $rps | Select -First 1 | %{ $_.GetRecoverySettings($pvm.Vm.MoRef) }

}

            

          $output = "" | select group, name, moRef, needsConfiguration, state, plans, priority, finalPowerState, preCallouts, postCallouts

$output.group = $pginfo.Name

$output.name = $pvm.Vm.Name

$output.moRef = $pvm.Vm.MoRef # this is necessary in case we can't retrieve the name when VC is unavailable

$output.needsConfiguration = $pvm.NeedsConfiguration

$output.state = $pvm.State

$output.plans = [string]::Join(",`r`n", $rpnames)

if ($rs) {

$output.priority = $rs.RecoveryPriority

$output.finalPowerState = $rs.FinalPowerState

$output.preCallouts = $rs.PrePowerOnCallouts.Count

$output.postCallouts = $rs.PostPowerOnCallouts.Count

}

$output

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

Name                           Port  User                         

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

htapll0201.example.com      443   VSPHERE.LOCAL\Administrator  

ServiceUri    : https://10.10.10.10:9086/vcdr/extapi/sdk

SessionSecret : "50a6cce4c29a11f90e35fc487575e1424036b786"

User          : administrator@vsphere.local

IsConnected   : True

Port          : 9086

Version       : 8.1.2

Build         : 12686166

ProductLine   : srm

InstanceUuid  : 9e240e3c-6c7e-4b8b-8170-7b33b39a4651

RefCount      : 4

ExtensionData : VMware.VimAutomation.Srm.Views.SrmServiceInstance

Uid           : /SrmServer=administrator@vsphere.local@10.10.10.10:9086/

Id            : /SrmServer=administrator@vsphere.local@10.10.10.10:9086/

Name          : 10.10.10.10

IsInUse       : True

ftsrmlapp301

Exception calling "GetRecoverySettings" with "1" argument(s): "Object

reference not set to an instance of an object."

At line:19 char:35

+ ... = $rps | Select -First 1 | %{ $_.GetRecoverySettings($pvm.Vm.MoRef) }

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

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

    + FullyQualifiedErrorId : NullReferenceException

group              : PBS pbsrmmuhp401 Prod PG

name               : ftsrmlapp301

moRef              : VirtualMachine-vm-301

needsConfiguration : False

state              : Ready

plans              : PBS pbsrmmuhp401 Prod RP

priority           :

finalPowerState    :

preCallouts        :

postCallouts       :

Reply
0 Kudos
5 Replies
mopa90001
Contributor
Contributor

I’m using the following Powershell script to get the Recovery setting of a protected VM, but I’m getting the error message in the output following the Powershell code below, can someone please tell me if there is something wrong with the script or the actual protected VM configuration on SRM 8.1.2 version?

Reply
0 Kudos
LucD
Leadership
Leadership

Two users with the same question at approximately the same time?

In any case, shouldn't that be

$_.GetRecoverySettings($pvm.MoRef)


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

Reply
0 Kudos
rami2aa
Contributor
Contributor

Hi LucD, there is no $PVM.Moref but there is $PVM.vm.moref you can try by your self if you want.

Reply
0 Kudos
KlonskyAdam
VMware Employee
VMware Employee

Run into same issue. After investigating, bug report has been submitted to engineering.

The workaround is to completely remove current PowerCLI and install PowerCLI 6.5.0R1

Procedures for uninstalling PowerCLI

  1. Open Powershell as Administrator.
  2. After opening PowerShell do not run any commands.
  3. Run code below several times (2-3) until all the VMware modules are removed.
  4. Get-InstalledModule VMware* | Uninstall-Module -Force
  5. Download PowerCLI 6.5.0R1 VMware-PowerCLI-6.5.0-4624819.exe from https://my.vmware.com/group/vmware/details?downloadGroup=PCLI650R1&productId=859
  6. Install PowerCLI 6.5.0R1 VMware-PowerCLI-6.5.0-4624819.exe
Reply
0 Kudos
rami2aa
Contributor
Contributor

Thank you KlonskyAdam, this solution made me to pass the error that I was getting, I was sure it was a bug that's why I posted my question here. I'll keep this thread active in case if I run into another error, so I'll let you know about it and if you can help me if possible. later on, for sure I'll mark your answer as the correct answer.

Reply
0 Kudos