Page 1 of 1

Powershell command to get connected ISCSI initiators

Posted: Fri Jul 20, 2018 2:24 pm
by webguyz
is there a powershell command to get all connected ISCSI initiators?

Thx.

Re: Powershell command to get connected ISCSI initiators

Posted: Fri Jul 20, 2018 2:33 pm
by Boris (staff)

Code: Select all

Get-IscsiConnection

Re: Powershell command to get connected ISCSI initiators

Posted: Fri Jul 20, 2018 2:39 pm
by webguyz
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?

Re: Powershell command to get connected ISCSI initiators

Posted: Fri Jul 20, 2018 3:13 pm
by Boris (staff)
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.

Re: Powershell command to get connected ISCSI initiators

Posted: Fri Jul 20, 2018 3:21 pm
by webguyz
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!

Re: Powershell command to get connected ISCSI initiators

Posted: Fri Jul 20, 2018 5:06 pm
by Boris (staff)
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.

Re: Powershell command to get connected ISCSI initiators

Posted: Tue Jul 24, 2018 6:16 pm
by webguyz
Was hoping to replicate the ISCSI info as in the attached from the Console Gui.

Re: Powershell command to get connected ISCSI initiators

Posted: Wed Jul 25, 2018 7:40 am
by Sekkmer
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

Re: Powershell command to get connected ISCSI initiators

Posted: Wed Jul 25, 2018 12:53 pm
by Boris (staff)
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.

Re: Powershell command to get connected ISCSI initiators

Posted: Wed Jul 25, 2018 1:10 pm
by webguyz
Perfect. Thanks all.

Re: Powershell command to get connected ISCSI initiators

Posted: Wed Jul 25, 2018 3:11 pm
by Boris (staff)
You are welcome.