Windows offers the iSCSI initiator applet, which enables configuring iSCSI connections interactively. However, if you want to automate connecting and disconnecting iSCSI targets, you can use PowerShell. It covers the functions of the GUI tool with its iSCSI module.
Latest posts by Wolfgang Sommergut (see all)

When you start the applet for the iSCSI initiator on a computer on which a connection has never been configured, you will receive a message that the iSCSI service is not running. If you prefer to use PowerShell instead of the GUI tool, then you have to take care of the prerequisites yourself.

Checking the prerequisites ^

The first step is to query the status of the iSCSI service:

Get-Service -Name MSiSCSI

If it turns out that the service has to be started, you can do this with the following command:

Start-Service -Name MSiSCSI

Next, change the start type to automatic, so that it will be executed again every time the computer is rebooted.

Set-Service -Name MSiSCSI -StartupType Automatic

If you are not sure whether there are already connections to an iSCSI target, you can check this using:

Get-IscsiTarget

In the following figure, the command returns a blank result. Hence, no connections exist.

Verify whether the MSiSCSI service is running and targets are already connected

Verify whether the MSiSCSI service is running and targets are already connected

Discovery of targets ^

To establish a new target, direct the initiator to the corresponding storage device. This is done by invoking:

New-IscsiTargetPortal -TargetPortalAddress "<IP or FQDN>"

This command uses the default initiator for the discovery process and default port 3260. Both can be specified using parameters, with Target¬Portal¬Port¬Number responsible for specifying the port.

If the client has more than one initiator, you can display them using the command:

iscsicli listinitiators

You then pass the desired one to the InitiatorInstanceName parameter:

New-IscsiTargetPortal -TargetPortalAddress "192.168.0.180" \`
-InitiatorInstanceName "ROOT\\ISCSIPRT\\0000\_0"
Invocation of New IscsiTargetPortal with the instance name of the initiator

Invocation of New IscsiTargetPortal with the instance name of the initiator

The next call to Get-IscsiTarget will provide the necessary information for the subsequent procedure. First and foremost, this includes the NodeAddress of the targets found. This is needed to establish a connection with the target.

Connect to a specific target by specifying a NodeAddress

Connect to a specific target by specifying a NodeAddress

In our example, the target is provided by a Synology NAS:

Connect-IscsiTarget -NodeAddress "iqn.2000-01.com.synology:DS214.Target-1.0e1a3dc1d1"

This command can be varied as needed. For example, the above call will only create a connection until the next reboot. If you want to make it permanent, then add the parameter -IsPersistent $true.

If you want to connect all available targets, then the following command does the job:

Get-IscsiTarget | Connect-IscsiTarget

Disconnect targets ^

The PowerShell module iSCSI also has cmdlets for the reverse operations. In our example, to terminate the connection to a target, you would issue the following command:

Disconnect-IscsiTarget -NodeAddress "iqn.2000-01.com.synology:DS214.Target-1.0e1a3dc1d1"

Finally, the target portal can be removed in this way:

Subscribe to 4sysops newsletter!

Remove-IscsiTargetPortal -TargetPortalAddress "192.168.0.180"

Here, be sure to specify the parameters in the same way as before for New- IscsiTargetPortal. If you used an IP for the portal address, then you should not specify a DNS name here. The same applies to the Initiator Instance Name. If you have originally passed one to the cmdlet, you have to do the same when you remove it.

0 Comments

Leave a reply

Your email address will not be published.

*

© 4sysops 2006 - 2022

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account