Configuration in VM to set up iSCSI initiator and cluster shared disks for SQL Server or File Server

The following script set contains the steps and introduction to perform the iSCSI configuration in the guest OS. Follow the steps on each Windows cluster node to get the disks ready for cluster services like SQL Server Failover Clustering Instance and Scale-Out File Server.

Note that the script needs the following running environment.

  • PowerShell 5.1 (use $PSVersionTable.PSVersion to check the version)
  • Windows Server 2016


iSCSI configuration steps in guest-OS using PowerShell

To configure the iSCSI initiator and to connect to the iSCSI target from vSAN6.7, follow the steps below.

Step 1. Enable cluster feature on Windows server to be as SQL Server Failover Clustering node.

Install-WindowsFeature -Name Failover-Clustering -IncludeAllSubFeature

Install-WindowsFeature -Name Failover-Clustering -IncludeManagementTools


Step 2. Enable Windows MPIO feature and explicitly set the failover policy to “Failover Only”

Use the sample code below to enable Windows MPIO feature and explicitly set the failover policy to “Failover Only”

Get-WindowsOptionalFeature -Online -FeatureName MultiPathIO

Install-WindowsFeature -name Multipath-IO

Enable-WindowsOptionalFeature -Online -FeatureName MultiPathIO -NoRestart

Enable-MSDSMAutomaticClaim -BusType iSCSI

#Set up the MPIO interval

Set-MPIOSetting -CustomPathRecovery Enabled -NewPathRecoveryInterval 20 -NewRetryCount 60 -NewPDORemovePeriod 60 -NewPathVerificationPeriod 30 -NewDiskTimeout 60

# As iSCSI service only supports active/passive HA; we must set the load balance policy as failover only. Use the following script to enable automatic identification on FOO for vSAN iSCSI target

mpclaim -l -t "VMware  Virtual SAN     "  1


Step 3.  Discover the target on each node of the Windows cluster and connect them

Use the sample code below to discover the target on each node of the cluster and connect them using multiple connections for failover purpose. 

Note: replace the IP address of the iSCSI vmk kernel IP address.  We use four hosts with vmk kernel ip address as an example.


foreach ($ip in $IPS){New-ISCSItargetportal -TargetPortalAddress $ip}

$targets=get-iSCSItarget | where isconnected -eq $False

$targets=get-iSCSItarget | where NodeAddress -like '*vmware:fs*'

$LocaliSCSIAddress=Get-NetIPAddress -AddressState  preferred -AddressFamily IPv4 -InterfaceAlias Ethernet0 -SkipAsSource $false |select -ExpandProperty IPAddress

Foreach ($ip in $IPS){

foreach ($tgt in $targets)


 Connect-ISCSITarget  -IsMultipathEnabled $true -TargetPortalAddress $ip -InitiatorPortalAddress $LocaliSCSIAddress -IsPersistent $true -nodeaddress $tgt.nodeaddress




Step 4.  Create the Windows cluster on node of the Windows cluster, test the nodes and create the cluster. We use two node cluster as an example.


Test-Cluster -Node “Windows_cluster_node1”, “Windows_cluster_node2

New-Cluster -Name “Windows_Cluster_name” -Node “Windows_cluster_node1” “Windows_cluster_node2” -StaticAddress “static_ip_address


Step 5.  Format the disks

You may use the script below to format disks and we recommend using friendly name and serial number to filter out the disks from vSAN iSCSI service.

Get-disk| Where-Object {($_.FriendlyName -like '*VMware Virtual SAN*') -and ($_.SerialNumber -like '*VITSERIAL*')} |

 initialize-disk -partitionstyle mbr -passthru |

    new-partition -assigndriveletter -usemaximumsize |

      format-volume -filesystem ntfs -AllocationUnitSize 65536 -confirm:$False


Step 6. Add disks to Windows cluster and get ready for usage for SQL Server or File Server

Get-ClusterAvailableDisk |Add-ClusterDisk



Sign in to be able to add comments.

Comments 0