Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
# create iSCSI Target
# [-TargetName] : any Target name
# [InitiatorId] : specify Initiators to allow to connect to Target
# for specifying Initiators, possible to specify methods like follows not only IPAddress
# ⇒ IPAddress, IPv6Address, DNSName, IQN, MACAddress
PS C:\Users\Administrator> New-IscsiServerTarget -TargetName "iSCSITarget01" -InitiatorId @("IPAddress:10.0.0.110","IPAddress:10.0.0.111")
ChapUserName :
ClusterGroupName :
ComputerName : rx-7.srv.world
Description :
EnableChap : False
EnableReverseChap : False
EnforceIdleTimeoutDetection : True
FirstBurstLength : 65536
IdleDuration : 00:00:00
InitiatorIds : {IPAddress:10.0.0.110, IPAddress:10.0.0.111}
LastLogin :
LunMappings : {}
MaxBurstLength : 262144
MaxReceiveDataSegmentLength : 65536
ReceiveBufferCount : 10
ReverseChapUserName :
Sessions : {}
Status : NotConnected
TargetIqn : iqn.1991-05.com.microsoft:rx-7-iscsitarget01-target
TargetName : iSCSITarget01
# create iSCSI virtual disk
# [-Path] : any PATH you'd like to create v-disk
# [-SizeBytes] : disk size
PS C:\Users\Administrator> New-IscsiVirtualDisk -Path "C:\iSCSIDisk\Disk01.vhdx" -SizeBytes 10GB
ClusterGroupName :
ComputerName : rx-7.srv.world
Description :
DiskType : Dynamic
HostVolumeId : {7B618CF5-8E74-4ED2-858A-78A97743E07D}
LocalMountDeviceId :
OriginalPath :
ParentPath :
Path : C:\iSCSIDisk\Disk01.vhdx
SerialNumber : B4038C72-8C4A-4F4F-9982-966BB22AE41A
Size : 10737418240
SnapshotIds :
Status : NotConnected
VirtualDiskIndex : 381244894
# assign iSCSI virtual disk to iSCSI Target
PS C:\Users\Administrator> Add-IscsiVirtualDiskTargetMapping -TargetName "iSCSITarget01" -Path "C:\iSCSIDisk\Disk01.vhdx"
# enable CHAP for iSCSI Target and set Username and Password for authentication
# replace "username", "UserP@ssw0rd01" below to your username and password
# required password length over 12 chars
PS C:\Users\Administrator> Set-IscsiServerTarget `
-TargetName "iSCSITarget01" `
-EnableChap $True `
-Chap (New-Object PSCredential("username", (ConvertTo-SecureString -AsPlainText "UserP@ssw0rd01" -Force)))`
-PassThru
# confirm settings
PS C:\Users\Administrator> Get-IscsiServerTarget -TargetName "iSCSITarget01"
ChapUserName : username
ClusterGroupName :
ComputerName : rx-7.srv.world
Description :
EnableChap : True
EnableReverseChap : False
EnforceIdleTimeoutDetection : True
FirstBurstLength : 65536
IdleDuration : 00:05:07
InitiatorIds : {IPAddress:10.0.0.110, IPAddress:10.0.0.111}
LastLogin :
LunMappings : {TargetName:iSCSITarget01;VHD:"C:\iSCSIDisk\Disk01.vhdx";LUN:0}
MaxBurstLength : 262144
MaxReceiveDataSegmentLength : 65536
ReceiveBufferCount : 10
ReverseChapUserName :
Sessions : {}
Status : NotConnected
TargetIqn : iqn.1991-05.com.microsoft:rx-7-iscsitarget01-target
TargetName : iSCSITarget01
# restart service
PS C:\Users\Administrator> Restart-Service -Name WinTarget
|