How to Configure a Windows Server iSCSI Target using PowerShell

The Power of Block-Level Storage

In a traditional Windows environment, you share storage over the network using SMB (Server Message Block) file shares. This is perfect for Excel documents and PDFs. However, if you are building a Hyper-V failover cluster or a high-availability SQL Server cluster, SMB shares are insufficient. Those enterprise applications require raw, block-level storage that looks and acts exactly like a local hard drive.

Historically, providing block-level storage required purchasing a $50,000 physical SAN (Storage Area Network) from EMC or NetApp. However, Windows Server includes a built-in feature called the iSCSI Target Server. This feature allows you to take a standard, cheap Windows Server filled with hard drives and transform it into a software-defined SAN, serving virtual hard disks (VHDXs) over the standard Ethernet network via the iSCSI protocol.

While you can configure this via the Server Manager GUI, PowerShell is essential for rapidly provisioning dozens of LUNs (Logical Unit Numbers) in a scalable data center.

Step 1: Installing the iSCSI Target Role

First, you must install the iSCSI Target role on your storage server (e.g., STORAGE-01). Open PowerShell as an Administrator and execute:

Install-WindowsFeature -Name FS-iSCSI-Target-Server -IncludeManagementTools

Step 2: Creating the Virtual Hard Disk (LUN)

In the iSCSI world, the actual storage payload is a VHDX file. The iSCSI service will mount this file and present it over the network as a raw block device.

To create a new 500GB dynamically expanding disk on the D: drive for your SQL cluster, execute:

New-IscsiVirtualDisk -Path "D:\iSCSIDisks\SQL-Data.vhdx" -Size 500GB

Step 3: Creating the iSCSI Target

The “Target” is the logical endpoint that the client servers (the Initiators) will connect to. You must give the Target a logical name.

New-IscsiServerTarget -TargetName "SQL-Cluster-Target"

Step 4: Mapping the Disk to the Target

Now, you must bind the VHDX file you created in Step 2 to the Target you created in Step 3.

Add-IscsiVirtualDiskTargetMapping -TargetName "SQL-Cluster-Target" -Path "D:\iSCSIDisks\SQL-Data.vhdx"

Step 5: Securing the Target (Authorizing Initiators)

If you stop here, your iSCSI target is sitting on the network, but no one can connect to it. By default, Windows blocks all connections for security. You must explicitly authorize the IP addresses or the IQNs (iSCSI Qualified Names) of the client servers that are allowed to mount this drive.

Assume you have two SQL servers (IPs 192.168.10.51 and 192.168.10.52) that need access to this shared disk.

Execute the following command to whitelist those specific IPs on the Target:

Set-IscsiServerTarget -TargetName "SQL-Cluster-Target" -InitiatorIds @("IPAddress:192.168.10.51", "IPAddress:192.168.10.52")

The software-defined SAN is now fully operational. You can log into your two SQL servers, open the iSCSI Initiator control panel, connect to STORAGE-01, and the 500GB disk will instantly appear in Disk Management as a raw, unformatted, locally attached physical hard drive.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.