Add iSCSI targets and set target parameter with PowerCLI
The code snippet in this blog post is an example of how to add iSCSI targets to an ESXi iSCSI initiator. But there is also a loop within processing a host, that sets iSCSI target parameter. For example this can be used when a storage vendor recommends to disable delayed acknowledgment per iSCSI target, like HPE does for 3PAR and LeftHand. Here you can see why it is recommended for 3PAR. In the code below, I do exactly that for LeftHand: disable delayed acknowledgment per target.
$iScsiTargetIp = "1.2.3.4" $iScsiTargetPort = "3260" $Cluster = Get-Cluster | Get-VMhost foreach ($VMhost in $Cluster) { $esxcli = $VMHost | Get-EsxCli -v2 $iScsiHBA = $VMhost | Get-VMHostHba -Type IScsi $iScsiHBA | New-IScsiHbaTarget -Address $iScsiTargetIp -Port $iScsiTargetPort $VMhost | Get-VMHostStorage -RescanAllHba -RescanVmfs foreach ($Target in ($esxcli.iscsi.adapter.target.portal.list.Invoke(@{"adapter"=$iScsiHBA.device}) | where {$_.id -like "*lefthandnetworks*" } )) { $esxcli.iscsi.adapter.target.portal.param.set.Invoke(@{"adapter"=$Target.Adapter; "address"=($Target.ip + ":" + $Target.port); "default"=$false; "inherit"=$false; "key"="DelayedAck"; "name"=$Target.target; "value"="false"}) } }
Short description by line number:
1,2: Enter IP addresses and ports of iSCSI targets.
4: Use $Cluster
to select hosts to run script for.
7: Target parameter are set by using esxcli
which is initialized here. V2
is the newer/current version.
9,10: Add target address to initiator.
12: Rescan for devices and VMFS, otherwise parameter cant be set.
14: Loops all targets containing lefthandnetworks in their iSCSI-name. For other vendors/models, this must be adjusted.
15: Sets parameter DelayedAck to false
and stops inheritance from iSCSI adapter.
Notes
- Code is tested for SW initiators.
[…] Here you can find how to disable delayed acknowledgement by using […]