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.

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:


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 "" \`
-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 ""

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 ""

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

Subscribe to 4sysops newsletter!

Remove-IscsiTargetPortal -TargetPortalAddress ""

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.

  1. John 9 months ago

    excellent description, thanks. I get a authorisation error when connting to linux based target. is there anyway to connect ? Microsoft unfortunately removed the iscsi app from Windows 11

  2. Eadweard 2 months ago

    Your shared article is very helpful, I am learning PowerShell to automate tasks. I’m from Mexico. Thank you

Leave a reply

Please enclose code in pre tags

Your email address will not be published.


© 4sysops 2006 - 2023


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


Log in with your credentials


Forgot your details?

Create Account