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 : {95471308-8C32-4533-A343-B2338BD6D05F}
LocalMountDeviceId :
OriginalPath :
ParentPath :
Path : C:\iSCSIDisk\Disk01.vhdx
SerialNumber : 237968DB-CBF0-49A4-BCE8-05270CF933A8
Size : 10737418240
SnapshotIds :
Status : NotConnected
VirtualDiskIndex : 864698100
# 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:01:26
InitiatorIds : {IPAddress:10.0.0.102, 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
|