PowerCLI

  • 1.  Cannot find an overload error

    Posted 15 days ago

    Hi all, does anyone know why this runs on one host, but not when I run it in a for-each loop?

    $vmhosts = Get-VMHost MyHost
    $esxcli = Get-EsxCli -VMHost ($vmhosts) -V2
    $naaID = "naa.####123"

    ForEach ($VMHost in $VMHosts)
    {
        
        #  Detach RDM
        Write-Host "Detaching $naaID from $VMHost"
        $esxcli.storage.core.device.set.Invoke(@{state="off"; device=$naaId})

    }

    The error is:

    Cannot find an overload for "Set" and the argument count: "1".
    At Remove stale detached RDMs from ESXi hosts.ps1:25 char:5
    +     $esxcli.storage.core.device.set.Invoke(@{state="off"; device=$naa ...
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodException
        + FullyQualifiedErrorId : MethodCountCouldNotFindBest



  • 2.  RE: Cannot find an overload error

    Posted 14 days ago

    Hi,

    You aren't setting $esxcli = Get-EsxCli -VMHost ($vmhosts) -V2 in your loop.  I haven't tested this but I'm pretty sure that's the issue.




  • 3.  RE: Cannot find an overload error

    Posted 14 days ago

    The real reason you get that error is because the Get-VMHost MyHost line returns more than 1 VMHost object.
    I tested it and got the same error message.

    The possible reasons you are getting more than 1 object returned:
    - there are multiple ESXi nodes with the name MyHost, which is very unlikely
    - you have multiple connections open, check what is in $global:defaultVIServers

    And yes, you should in that case place the Get-EsxCli line inside the loop.



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


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


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