It also work on a datacenter

Param ($cluster = "")
#$cluster = "vmcluster"
$iscsiHba = "vmhba32" #might be vmhba33
$iscsiServer = "iscsi_ip"
$iscsiPort = 3260
$target = New-Object VMware.Vim.HostInternetScsiHBASendTarget
$target.address = $iscsiServer
$target.port = $iscsiPort
$iscsiauthprop = New-Object VMware.Vim.HostInternetScsiHbaAuthenticationProperties
#$iscsiauthprop.ChapAuthEnabled = "true"
#$iscsiauthprop.ChapName = "user"
#$iscsiauthprop.ChapSecret = "password"
$h = Get-VMHost -Location $cluster
Foreach ($hostView in ( Get-View -VIObject $h)) {
$storageSystem = Get-View $hostView.configManager.storageSystem
# Enable software iSCSI controller
$storageSystem.UpdateSoftwareInternetScsiEnabled($true)
# Add iSCSI Server for dynamic discovery
$storageSystem.AddInternetScsiSendTargets($iscsiHba, $target)
$storageSystem.UpdateInternetScsiAuthenticationProperties($iscsiHba,$iscsiauthprop)
# Scan for iSCSI devices
$storageSystem.RescanHba($iscsiHba)
}
Thanks to
http://doitsmarter.blogspot.com/2009/02/esx-iscsi-enable-script-using-vi.htmlI just add the "-location" for the cluster/datacenter way