# found https://vmscribble.com/
# ref https://infosight.hpe.com/InfoSight/media/cms/active/public/pubs_VMware_Integration_Guide_NOS_50x.whz/cwz1530912931494.html
Write-Host ""
Write-Host "This script will change the iSCSI LoginTimeout NoopOutTimeout NoopOutInterval values to 30 seconds on ALL connected ESXi hosts in the cluster." -foregroundcolor White
Write-Host "Please REBOOT each host for the changes to take effect." -foregroundcolor Yellow
Read-Host "Press Enter to continue"
# Set Variables
$vCenter = Read-Host "Enter the vCenter Name"
$ClusterName = Read-Host "Enter the Cluster Name"
$thirty = "30"
Write-Host ""
# Connect to your vCenter
Connect-VIServer $vCenter | out-null
# list all connected ESXi hosts
$AllHosts = Get-Cluster $ClusterName | Get-VMhost | where {($_.ConnectionState -eq "Connected")} | sort-object Name
# Change
foreach($esxihost in $AllHosts){
$iscsi_hbas = $esxihost | get-vmhosthba -type iscsi
if($iscsi_hbas -eq $null){
write-host "$esxihost does not have an iSCSI adapter"
}
else{
foreach($hba in $iscsi_hbas){
$esxcli = get-esxcli -vmhost $esxihost
$esxcli.iscsi.adapter.param.set($hba.device,$false,'LoginTimeout',$thirty) | out-null
write-host "$esxihost $hba - Setting LoginTimeout to 30" -foregroundcolor White
$esxcli.iscsi.adapter.param.set($hba.device,$false,'NoopOutTimeout',$thirty) | out-null
write-host "$esxihost $hba - Setting NoopOutTimeout to 30" -foregroundcolor White
$esxcli.iscsi.adapter.param.set($hba.device,$false,'NoopOutInterval',$thirty) | out-null
write-host "$esxihost $hba - Setting NoopOutInterval to 30" -foregroundcolor White
}
}
}
# Validation
Write-Host ""
Write-Host "Validating ESXi hosts:"
foreach($esxihost in $AllHosts){
$iscsi_hbas = $esxihost | get-vmhosthba -type iscsi
if($iscsi_hbas -eq $null){ write-host "$esxihost does not have an iSCSI adapter"}
else{
foreach($hba in $iscsi_hbas){
$esxcli = get-esxcli -vmhost $esxihost -V2
$esxcli.iscsi.adapter.param.get.Invoke(@{adapter = "$hba"}) | select Name, Current | where Name -match "LoginTimeout"
$esxcli.iscsi.adapter.param.get.Invoke(@{adapter = "$hba"}) | select Name, Current | where Name -match "NoopOutTimeout"
$esxcli.iscsi.adapter.param.get.Invoke(@{adapter = "$hba"}) | select Name, Current | where Name -match "NoopOutInterval"
Write-Host "$esxihost"
Write-Host ""
}
}
}
# Disconnect from the vCenter
Disconnect-VIServer $vCenter -Confirm:$false