Powershell command to get connected ISCSI initiators

Software-based VM-centric and flash-friendly VM storage + free version

Moderators: anton (staff), art (staff), Max (staff), Anatoly (staff)

Post Reply
webguyz
Posts: 23
Joined: Sat Jan 26, 2013 12:34 am

Fri Jul 20, 2018 2:24 pm

is there a powershell command to get all connected ISCSI initiators?

Thx.
Boris (staff)
Staff
Posts: 805
Joined: Fri Jul 28, 2017 8:18 am

Fri Jul 20, 2018 2:33 pm

Code: Select all

Get-IscsiConnection
webguyz
Posts: 23
Joined: Sat Jan 26, 2013 12:34 am

Fri Jul 20, 2018 2:39 pm

Boris (staff) wrote:

Code: Select all

Get-IscsiConnection
Hmm. Don't see that command in the Starwindx\Samples\powershell folder. Where might I find it?
Boris (staff)
Staff
Posts: 805
Joined: Fri Jul 28, 2017 8:18 am

Fri Jul 20, 2018 3:13 pm

I might be misunderstanding your aim. This command is a part of the standard PowerShell inventory, not related to StarWind exclusively.
Tell me what you are trying to achieve for me to give you a more appropriate solution.
webguyz
Posts: 23
Joined: Sat Jan 26, 2013 12:34 am

Fri Jul 20, 2018 3:21 pm

I have a 2 node Starwind Free setup with separate compute and storage with HA being used with VMware. I want to find out the VMware inititators connected to a particular target given a iqn number like
iqn.2008-08.com.starwindsoftware.SAN1

Thanks!
Boris (staff)
Staff
Posts: 805
Joined: Fri Jul 28, 2017 8:18 am

Fri Jul 20, 2018 5:06 pm

I could suggest going a bit different way.

Code: Select all

Connect-VIServer 10.10.10.10
$esxcli = Get-EsxCli
$esxcli.iscsi.session.connection.list.Invoke() | select Adapter,Target,State | Where {$_.Target -eq "your_target_name"}
When used with the vCenter, it should show whether that particular target is connected to the host.
webguyz
Posts: 23
Joined: Sat Jan 26, 2013 12:34 am

Tue Jul 24, 2018 6:16 pm

Was hoping to replicate the ISCSI info as in the attached from the Console Gui.
Attachments
iscsi sessions.PNG
iscsi sessions.PNG (24.74 KiB) Viewed 6845 times
Sekkmer
Posts: 29
Joined: Thu Mar 08, 2018 12:11 pm

Wed Jul 25, 2018 7:40 am

IStarWindServer has a function GetInitiators(string TargetId) witch return a collection of strings like the GUI.

usage: $server.GetInitiators("0x...")

then you just have to iterate over the return
Boris (staff)
Staff
Posts: 805
Joined: Fri Jul 28, 2017 8:18 am

Wed Jul 25, 2018 12:53 pm

Sekkmer,

Thanks for mentioning it. You are completely right. The example code will be like below:

Code: Select all

Import-Module StarWindX

$iqn = "your_StarWind_target_IQN"
$server = New-SWServer -host 127.0.0.1 -port 3261 -user root -password starwind
$server.Connect()
$target = $server.Targets | Where {$_.Name -eq $iqn} | Select-object -ExpandProperty ID
$server.GetInitiators($target) | Where {$_.Name -like "*vmware*"}
It will output the names of initiators connected to the particular target. I hope this is what you were going to achieve.
webguyz
Posts: 23
Joined: Sat Jan 26, 2013 12:34 am

Wed Jul 25, 2018 1:10 pm

Perfect. Thanks all.
Attachments
initiators.PNG
initiators.PNG (20.82 KiB) Viewed 6827 times
Boris (staff)
Staff
Posts: 805
Joined: Fri Jul 28, 2017 8:18 am

Wed Jul 25, 2018 3:11 pm

You are welcome.
Post Reply