SRM-Cmdlets icon indicating copy to clipboard operation
SRM-Cmdlets copied to clipboard

Get-UnprotectedVM gives error on datastore

Open nirajshrestha opened this issue 10 years ago • 2 comments

in array based replication, following error gets generated when we run Get-UnprotectedVM Get-VM : Cannot bind parameter 'Datastore'. Cannot convert the "VMware.Vim.Datastore" value of type "VMware.Vim.Datastore" to type "VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.StorageResource". At C:\tools\SRMProtection\SRMFunctions.ps1:198 char:51

  •         $associatedVMs += @(Get-VM -Datastore $ds)
    
  •                                               ~~~
    
    • CategoryInfo : InvalidArgument: (:) [Get-VM], ParameterBindingE xception
    • FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomat ion.ViCore.Cmdlets.Commands.GetVM

nirajshrestha avatar Sep 21 '14 04:09 nirajshrestha

I had to update the code to get the datastore names from the id

TODO test this: For ABR get VMs on GetProtectedDatastore

    if ($pg.GetInfo().Type -eq 'san') {
        $ds = @(Get-ProtectedDatastore -ProtectionGroup $pg)
        $ds | foreach {
        $dsname = Get-Datastore -id $_.MoRef
        $associatedVMs += @(Get-VM -Datastore $dsname)
        }
    }

And i call the function as below

Get-ProtectionGroup | %{ $pg = $_ Get-UnProtectedVM -ProtectionGroup $pg } | %{ $output = "" | select VmName, PgName $output.VmName = $.Name $output.PgName = $pg.GetInfo().Name $output } | Format-Table @{Label="VM Name"; Expression={$.VmName} }, @{Label="Protection group name"; Expression={$_.PgName} }

nilanshakya avatar Sep 21 '14 15:09 nilanshakya

Thank you both for first raising the issue and then for the suggested fix.

Unfortunately I don't have an ABR setup with SRM at the moment to test this fix, however it looks like the issue appears to be with the results of the protected datastores so using the MoRef to workaround that as suggested should be a pragmatic approach. I've made a change to the code similar to this suggestion, I'll revisit this again when I have my ABR lab set up and I can test this more thoroughly.

Thanks again.

benmeadowcroft avatar Sep 24 '14 00:09 benmeadowcroft