Your foreach loop does not include the method call.
You should use $item (a single ESXi node) and not $hosts (all ESXi nodes in the cluster) inside the foreach loop.
Try like this
[parameter(Mandatory = $true
, HelpMessage = "VC Name")]
[string] $VC
, [parameter(Mandatory = $true
, HelpMessage = "Cluster Name")]
[string] $cluster
)
$svr = $null;
$svr = Connect-VIServer -Server $VC;
if ($svr -eq $null) {
$sMsg = "Unable to connect to VC " + $VC;
exit 1;
}
$sMsg = "Getting cluster " + $cluster + " on VC " + $VC;
Write-Host $sMsg;
$oClstr = $null;
$oClstr = Get-Cluster -Server:$svr -Name $cluster;
if ($oClstr -eq $null) {
$sMsg = "Unable to find cluster " + $cluster + " on VC " + $VC;
$iret1 = Disconnect-VIServer -Server:$svr -Confirm:$false -ErrorAction:SilentlyContinue;
exit 1;
}
$sMsg = "Getting hosts on cluster " + $cluster + " on VC " + $VC;
write-host $sMsg;
$options = New-Object VMWare.Vim.HostInternetScsiHbaParamValue[] (1)
$options[0] = New-Object VMware.Vim.HostInternetScsiHbaParamValue
$options[0].key = "DelayedAck"
$options[0].value = $false
$hosts = Get-VMHost -Location $oClstr -Server:$svr;
foreach ($item in $hosts) {
$sMsg = "Processing host " + $item.Name + " in cluster " + $cluster + " on VC " + $VC;
write-host $sMsg;
$HostStorageSystemID = $item.EXtensionData.configmanager.StorageSystem
$HostiSCSISoftwareAdapterHBAID = ($item.EXtensionData.config.storagedevice.HostBusAdapter |
where { $_.Model -match "iSCSI Software" }).device
$HostStorageSystem = Get-View -ID $HostStorageSystemID
$HostStorageSystem.UpdateInternetScsiAdvancedOptions($HostiSCSISoftwareAdapterHBAID, $null, $options)
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference