WS2012 Storage - iSCSI Target Server - Create an iSCSI target using PowerShell
For my Virtual Machines needs, some LUNS are presented to my VMware vSphere 5.1 Servers and until now,my labstorage was handle byFreeNas using iSCSI.
For tests purposes, I replaced this FreeNas by Windows Server 2012 to take care of that part.
Note: Before writing this post, I grouped my physical disks together into a container called storage poolsto manage those disks as a single storage space. Afterwards, in these storage pools, I created virtual disks (aka LUN)on which I specify a layout, … which is simply a raid level.
OverviewPermalink
In the following post I will talk about the following points:
-
Quick iSCSI Terminology
-
Quick look at iSCSI Target Management (GUI and PowerShell iSCSI Modules)
-
Installing the Windows Feature iSCSI Server Target (PowerShell)
-
Creating a iSCSI Virtual Disk (aka LUN) (PowerShell)
-
Creating a iSCSI Target and assigning it to one or more initiator(s) (PowerShell)
-
Finding the iSCSI Qualified Name (IQN)</b> (vSphere Client and PowerCLI)
-
Assigning a iSCSI Virtual Disk (LUN) to a iSCSI Target (PowerShell)
TerminologyPermalink
Note: The iSCSI protocol is fully documented by the RFC 3720and RFC 3721 iSCSI:iSCSI stands forInternet Small Computer System Interface. It’s an Internet Protocol (IP)-based storage networking standard for linking data storage facilities. iSCSI is used to facilitate data transfers over a network (LAN, WAN or Internet) and transferring data by carrying SCSI commands over IP networks. iSCSI leverages the Ethernet network and does not require any specialized hardware
![]() |
source:[http://blogs.technet.com/b/filecab/](http://blogs.technet.com/b/filecab/) |
iSCSI Target Server: is the server that shares the storage, it runs the iSCSI Target. The server (machine) consumes the storage is called iSCSI initiator.
iSCSI Initiator:Typically, it is an application server. For example, iSCSI Target provides storage to a SQL server, the SQL server will be the iSCSI initiator in this deployment.
Target: It is an object which allows the iSCSI initiator to make a connection. The Target keeps track of the initiators which are allowed to be connected to it. The Target also keeps track of the iSCSI virtual disks which are associated with it. Once the initiator establishes the connection to the Target, all the iSCSI virtual disks associated with the Target will be accessible by the initiator.
iSCSI Virtual Disk: It also referred to as iSCSI LUN. It is the object which can be mounted by the iSCSI initiator. On Windows Server 2012, the iSCSI virtual disk is backed by the VHD file.
iSCSI Connection: iSCSI initiator makes a connection to the iSCSI Target Server by logging on to a Target. There could be multiple Targets on the iSCSI Target Server, each Target can be accessed by a defined list of initiators. Multiple initiators can make connections to the same Target. However, this type of configuration is only supported with clustering. Because when multiple initiators connects to the same Target, all the initiators can read/write to the same set of iSCSI virtual disks, if there is no clustering (or equivalent process) to govern the disk access, corruption will occur. With Clustering, only one machine is allowed to access the iSCSI virtual disk at one time.
IQN:iSCSI Qualified Name. It is a unique identifier of the Target or Initiator. The Target IQN is shown when it is created on the Server. The initiator IQN can be found by typing a simple “iscsicli” cmd in the command window or using Get-InitiatorPort in PowerShell
![]() |
Using iscsicli |
![]() | ||
Using PowerShell (module iSCSI) with the Cmdlet Get-InitiatorPort</td></tr></tbody></table>
Briefly, the fields are:
* The string "iqn.", used to distinguish these names from "eui." formatted names.
* A date code, in yyyy-mm format that the naming authority took ownership of the domain
* The reversed domain name of the naming authority (person or organization) creating this iSCSI name. (com.lazywinadmin, com.example, com.google)
* An optional, colon (:) prefixing a storage target name specified by the owner of the domain name deems appropriate.
Information from the RFC:
![]() The UI integrated to Service Manager
Once you installed the Windows Feature for iSCSI Target Server you will see a new menu under File and Storage Services
PowerShell Cmdlets
Windows Server 2012 comes with a complete set of PowerShell cmdlets for iSCSI. By combining the iSCSI target, iSCSI initiator, and storage cmdlets, you can automate pretty much all management tasks.Here is the list of Cmdlets available to you:
![]() ![]() 3 - Create a Target
Here we create a new iSCSI target object with the name "TestTarget1" specified by the-TargetNameparameter. The -InitiatorIdsparameter stores the initiators which can connect to the Target.
```
# Creating a iSCSI Target. I specify the IPAddresses of the Initiator Hosts (192.168.1.101 and 192.168.1.102) which are VMware vSphere Hosts.
New-IscsiServerTarget -TargetName TestTarget1 -InitiatorId IPAddress:192.168.1.101,IPAddress:192.168.1.102
```
```
```
Optionally:Instead of the iSCSI Initiator's IPAddress you can also specify the IQN:
```
New-IscsiServerTarget -TargetName TestTarget1 -InitiatorId "IQN:iqn.1998-01.com.vmware:LAB1VH01-675d7f45"
```
```
```
![]() No output will be generated.
There is no Passthru parameter either :-(</td></tr></tbody></table>
Optionally:You can specify the Logical Unit Number (LUN) associated with the virtual disk. By default, the lowest available LUN number will be assigned.
```
# Assigning the virtual disk to the iSCSI Target
Add-IscsiVirtualDiskTargetMapping -TargetName TestTarget1 -Path C:\test\Lun1.vhd -Lun 25
```
| ![]() |



Leave a comment