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
------------------------------
Original Message:
Sent: Feb 28, 2025 01:54 PM
From: svillar
Subject: Cannot find an overload error
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