Skip to content

Configure ESXi Path Selection and iSCSI software adapter with PowerCLI

In the past few weeks I’ve worked more with PowerCLI because I wanted to automate some of the settings and configuration of newly installed ESXi hosts. One of the things was to set the Path Selection Policy to Round Robin and set iSCSI vmk qDepth to 32.

So, this script will change the default PSP to RR, change the iscsivmk qDepth and in the end it will enable the iSCSI software adapter.

I parameterised  vCenter and cluster name so it would be easier when running the script, and after that set the arguments for the defaultpsp, SATP and iscsivmk settings. You can change the arguments values based on your storage provider recommendation.

 param(
$vcenter,
$clustername
)
Connect-VIServer $vcenter
$Cluster = Get-Cluster -Name $clustername | Get-VMhost
$args1 = @{
    defaultpsp = 'VMW_PSP_RR'
    satp = 'VMW_SATP_ALUA'
}
 
$qDepth = @{
   module = 'iscsi_vmk'
   parameterstring = 'iscsivmk_LunQDepth=32'
}
 
foreach ($ESXHost in $Cluster) {
$esxcli = $ESXHost | Get-EsxCli -v2
 
$esxcli.storage.nmp.satp.set.invoke($args1)
 
$esxcli.system.module.parameters.list.Invoke(@{module='iscsi_vmk'})
$esxcli.system.module.parameters.set.Invoke($qDepth)
$esxcli.system.module.parameters.list.Invoke(@{module='iscsi_vmk'})
 
Get-VMHostStorage -VMHost $ESXHost | Set-VMHostStorage -SoftwareIScsiEnabled $True
} 
 

Thanks Luc Dekens for the help provided with this script.

The next blogpost will be about how to set the iSCSI Targets using PowerCLI.

Published inGeneral

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.