I am trying to run this simple script
$srmApi = $srm.ExtensionData
$protectionGroups = $srmApi.Protection.ListProtectionGroups()
$protectionGroups | % {
$protectionGroup = $_
$protectionGroupInfo = $protectionGroup.GetInfo()
$protectedVms = $protectionGroup.ListAssociatedVms() ##Fails
$protectedVms | % { $_.Vm.UpdateViewData() }
$protectedVms | %{
$output = "" | select VmName, PgName
$output.VmName = $_.Vm.Name
$output.PgName = $protectionGroupInfo.Name
$output
}
}
However, I get the error -
Exception calling "ListAssociatedVms" with "0" argument(s): "The operation is not supported on the object."
+ $protectionGroups[0].ListAssociatedVms <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
The ListAssociatedVms method does exist as piping $protectionGroups[0] | gm shows it as a valid method.
Any ideas?
We are using vSphere Server 5.0.0 with PowerCli 5.5
Thanks in advance,
Jake
Also, if I use ListProtectedVms instead of ListAssociatedVms, I get the next error -
Method invocation failed because [VMware.VimAutomation.Srm.Views.SrmProtectionGroupProtectedVm] doesn't contain a method named 'UpdateViewData'.
Is something missing???
Could it be that you have more than 1 object in $protectionGroup ?
If yes, you would have to loop through each element in the array.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I dont think so LucD. But now I am wondering if its a version issue of the vCenter/SRM. I think we have version 5.0 update 3.
VMware vSphere PowerCLI 5.5 Release 2 supports the following VMware environments:
vCloud Director PowerCLI 5.5 is compatible with VMware vCloud Director 1.5.1, VMware vCloud Director 5.1, and VMware vCloud Director 5.5. Note: You can automate only vCloud Director 5.1 features against vCloud Director 5.5.
VMware vSphere PowerCLI 5.5 Release 2 is compatible with vCenter Site Recovery Manager 5.5.
VMware vSphere PowerCLI 5.5 Release 2 is compatible with the following PowerShell versions:
Could be a version thing, but that method seems to be supported since API 5.0, so that should work (I think)
I'm a bit confused by the code you showed, there it says
$protectionGroup.ListAssociatedVms()
while the error message says
$protectionGroups[0].ListAssociatedVms
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
You are right... the error message I pasted was for a different execution. Sorry about that. Here is the error
Exception calling "ListAssociatedVms" with "0" argument(s): "The operation is not supported on the object."
At E:\data\ps\SRMList.ps1:10 char:46
+ $vms = $protectionGroup.ListAssociatedVms <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
It seems like the execution of the method is failing rather than the method being non-existent (as verified by gm)
Jake.
Can you show the output of the "$protectionGroups[0] | gm" command? It looks like the ListAssociatedVms() method needs a parameter. In the
"Site Recovery Manager API Developer’s Guide, VMware vCenter Site Recovery Manager 5.0" (https://www.vmware.com/support/developer/srm-api/srm_50_api.pdf) a "managed object reference to an SrmProtectionGroup object" is used as a parameter.
No it doesn't, as is shown in Create a Report of the Virtual Machines Associated with All Protection Groups
But I agree that it could be a version issue.
You did do the Connect-SrnServer I assume ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
RvdNieuwendijk - I checked the gm and it doesn't take a parameter.
LucD - Yes, did do the connect-SRMServer to start with.
This sounds like a version issue as I dont see any other references to this error.....:(
Anyone getting error when UpdateViewData method is called for a list of protected VM's? Below is the error i am getting. Running Powershell 5.5 R2 and SRM 5.1.2 versions. Just curious if anyone getting the same error.
I found another way to get the list though (see below for code).
Exception calling "UpdateViewData" with "0" argument(s): "The object has already been deleted or has not been completely created"
At line:1 char:25
+ $protectedVms | % { $_.Vm.UpdateViewData() }
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Exception calling "UpdateViewData" with "0" argument(s): "The object has already been deleted or has not been completely created"
At line:1 char:25
+ $protectedVms | % { $_.Vm.UpdateViewData() }
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Currently working Code:
$srm =Connect-srmserver -Server vcenter -User username -Password password
$srmApi = $srm.ExtensionData
$srmApi.Protection.ListProtectionGroups() | % {
$protectionGroup = $_
$protectionGroupInfo = $protectionGroup.GetInfo()
$protectionGroup.ListProtectedVMs() | % {$_.vm.moref.tostring()} | % {
$vm = (get-vm -id $_).name
New-Object PSObject |
Add-Member -pass NoteProperty ProtectionGroup $ProtectionGroupInfo.Name |
Add-Member -pass NoteProperty ProtectedVM $VM
}
} | sort ProtectionGroup,ProtectedVM | ft -a
I had the same issue yesterday.
SRM is very particular with how you connect to it, this is how I ended up doing it.
Connect-VIServer <vcfqdn>
$srm=Connect-SrmServer
When I was specifying the srm server, i ran into issues.
Was this issue ever resolved? I am running into the same problem but it can't be a version issue since we are running SRM 5.5.
I get this error: "The operation is not supported on the object" on every method in the protectiongroup object. So for .ListAssociatedVms and for .AssociateVms etc..
No...this was not resolved for me. However, a couple of days we upgraded to 5.5....so I shall check to see if its working now and reply back.
Update: My permissions were stripped during the upgrade. Trying to get it re-instated. Then will test.
thanks! Curious to hear the rusults.
I'll do some further digging today to find out what's causing this.
In the mean time: Anybody else with a bright idea?
I'm trying to execute this example code from the manual:
Connect-VIServer -Server vc3.example.com -User 'MyAdministratorUser' -Password 'MyPassword'
$srm = Connect-SrmServer -RemoteUser 'MyRemoteUser' -RemotePassword 'MyRemotePassword'
$srmApi = $srm.ExtensionData
$protectionGroups = $srmApi.Protection.ListProtectionGroups()
$vmToAdd = Get-VM "TestVM"
$targetProtectionGroup = $protectionGroups | where {$_.GetInfo().Name -eq "ProtGroup1" }
$targetProtectionGroup.AssociateVms(@($vmToAdd.ExtensionData.MoRef))
$protectionSpec = New-Object VMware.VimAutomation.Srm.Views.SrmProtectionGroupVmProtectionSpec
$protectionSpec.Vm = $vmToAdd.ExtensionData.MoRef
$protectTask = $targetProtectionGroup.ProtectVms($protectionSpec)
while(-not $protectTask.IsComplete()) { sleep -Seconds 1 }
Which fails with this error: "The operation is not supported on the object" on this line: $targetProtectionGroup.AssociateVms(@($vmToAdd.ExtensionData.MoRef))
already tried passing local and remote credentials to connect-srmserver but that doesn't help.
This script is running on a vCO server and not on the SRM server locally. (because there is no SRM plugin for vCO this seems to be the only way to integrate SRM with vCO)
Got my access back....but does not work with 5.5 either.....weird!
Update - so using the pipe to gm I can see that there is no ListAssociatedVms method .... only a ListProtectedVms method exists. Wonder why the sample code uses a method that does not exist...
Update 2 - Was reading in the Developer API Guide that "You can use these methods with vSphere replication (VR) but not with array based replication." Maybe that is my problem.
yep, that was the problem. Don't need to associate the VM, just protect it.
That resulted in another error which made me to believe I really needed the associateVms but I was wrong.
Leaving out the the associateVms line resulted in an authentication error on the vCenter job. That was solved by passing a pscredential object for both remote and local srm machine to connect-sermserver.
I'm working on a blog post explaining what I did exactly and how to call it from vCO. Will post the link when it's online.
Here is my blog post describing how I used PowerCLI to automate the protection of VMs with SRM.
Thanks for the writeup Croeleveld.
Also wanted to add that one can get the VM name from the Protected VM name in a roundabout way.
You get cryptic names from the ListProtectedVms method such as protected-vm-12345. To get the actual VM, do the following - get the MORef (Managed Object Reference) for the protected VM as $protectedVM.Vm.MoRef
You can then run the get-VM cmdlet searching for VM with matching ExtensionData.MoRef
Try to connect to the other site instead. Some operations are valid on a particular site only. If the operation requires access to the remote site, you need to specify the RemoteUsername and RemotePassword parameters.
If you get that the object is missing or deleted, you are probably trying to get an object (like VM) from the wrong VC (site).
If you get that the operation is not supported, the object might be in a state or site that cannot process the operation.
If you get that there is no such method, you probably are trying to call a method on an array instead of on an element in that array.
Hi jake1973,
My goal is to list all VMs that are protected by SRM. I'm able to list Protected VMs with $ProtectionGroups.ListProtectedVMs() and get something like:
Vm : VMware.Vim.VirtualMachine
ProtectedVm : protected-vm-59441
PeerProtectedVm : protected-vm-59404
State : Ready
PeerState : Shadowing
NeedsConfiguration : False
Faults
DynamicType
DynamicProperty
Could you please elaborate on how to turn a protected-vm-59441 into a "normal" VM name?
Many thanks