Configure iSCSI Initiator Target Portals with Powershell

By default when you discover target portals with the iSCSI Initiator, the default values will be on “Default” for Local adapter and Initiator IP.
iSCSI

To make sure the initiator is using the right IP addresses and NICs, and overcome connections problems, you will need to set the local adapter and initiator IP static.
Ofcourse you can do this by clicking in the GUI, but I like powershell better.

$TargetPortal1 = "10.0.1.1"
$TargetPortal2 = "10.0.1.2"
$ISCSIIP1 = (Get-NetIPAddress -InterfaceAlias "NIC1" -AddressFamily IPv4).IPAddress
$ISCSIIP2 = (Get-NetIPAddress -InterfaceAlias "NIC2" -AddressFamily IPv4).IPAddress


New-IscsiTargetPortal -TargetPortalAddress $TargetPortal1 -InitiatorPortalAddress $ISCSIIP1 -InitiatorInstanceName "ROOT\ISCSIPRT\0000_0"
New-IscsiTargetPortal -TargetPortalAddress $TargetPortal2 -InitiatorPortalAddress $ISCSIIP2 -InitiatorInstanceName "ROOT\ISCSIPRT\0000_0"

Start-sleep -seconds 2

$targets = Get-IscsiTarget
foreach ($target in $targets)
    {
    Connect-IscsiTarget -IsMultipathEnabled $true -NodeAddress $target.NodeAddress -IsPersistent $true
    }

Leave a Reply

Your email address will not be published. Required fields are marked *