VMware Cloud Community
EddiePJ
Enthusiast
Enthusiast
Jump to solution

Extract iSCSI device path from a list

Hi,

Can someone please assist on how to extract a particular device name (eg. a device path that contains "clone" string) from an iSCSI software storage adapter. Below is the script that I found in the internet that extracts the devise attached to the iSCSI HBA adapter but I am having a hard time creating the logic.

$esxImpl = Get-VMHost -Name

$storImpl = Get-VMHostStorage -VMHost $esxImpl

stor = get-view $storImpl.ID

Foreach($adapter in $stor.StorageDeviceInfo.ScsiTopology.Adapter){

  foreach($target in $adapter.Target){

  $nimblevolname = $target.Transport.IScsiName

  Write-Host $nimblevolname

  Write-Host $nimblevolname | where{$_.$nimblevolname -like "*clone"}

}

}

Thanks.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

With a Where-clause you should be able to do it like this

$esxImpl = Get-VMHost -Name MyEsx

$storImpl = Get-VMHostStorage -VMHost $esxImpl

$stor = Get-View -Id $storImpl.ID

Foreach($adapter in $stor.StorageDeviceInfo.ScsiTopology.Adapter){

    foreach($target in $adapter.target){

        $target.Transport | where{$_.IscsiName -match "clone"} | Select IScsiName

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

11 Replies
LucD
Leadership
Leadership
Jump to solution

Isn't his giving you the required info ?

Get-VMHost -Name MyEsx |

Get-IScsiHbaTarget |

Select Name,Type,iSCSIHbaName,Address,Port


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
EddiePJ
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

It will but I want to extract a particular device path which contains a particular string (eg. clone) from the device list. The main objective is to extract a specific device path which I will extract the alias or canonical name so that I can mount it on a VM as a VHD.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can do that by inserting a Where-clause.

Which of the properties actually contains the string you want to filter upon?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
EddiePJ
Enthusiast
Enthusiast
Jump to solution

The TARGET under the PATHS tab of the iSCSI Software Adapter details (see screenshot below)

pastedImage_0.png

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I meant, is that string visible under any of the properties that are on the Select -Object cmdlet of the code I gave?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
EddiePJ
Enthusiast
Enthusiast
Jump to solution

No it is not visible. The only (I think) way to get the device path name is by the script I mentioned at the beginning. It will have the same detail as the screenshot I sent previously.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Does this give you the desired entry?

$esxImpl = Get-VMHost -Name MyEsx

$storImpl = Get-VMHostStorage -VMHost $esxImpl

$stor = Get-View -Id $storImpl.ID

$stor.StorageDeviceInfo.HostBusAdapter | where{$_.IScsiName -like "*clone"}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
EddiePJ
Enthusiast
Enthusiast
Jump to solution

Does not display anything. I manage to extract the particular device path name by using IF...

...

$nimblevolname = $target.Transport.IScsiName

  if($nimblevolname -match "clone") {

  Write-Host $nimblevolname

...

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

With a Where-clause you should be able to do it like this

$esxImpl = Get-VMHost -Name MyEsx

$storImpl = Get-VMHostStorage -VMHost $esxImpl

$stor = Get-View -Id $storImpl.ID

Foreach($adapter in $stor.StorageDeviceInfo.ScsiTopology.Adapter){

    foreach($target in $adapter.target){

        $target.Transport | where{$_.IscsiName -match "clone"} | Select IScsiName

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

EddiePJ
Enthusiast
Enthusiast
Jump to solution

Thanks LucD. That is a more efficient code. Cheers!

Reply
0 Kudos
EddiePJ
Enthusiast
Enthusiast
Jump to solution

Hi,

Im on a gun on this script. Now that I have extracted the particular device path, how can I know the alias or canonical name of the IscsiName that I have extracted? Thanks.

Reply
0 Kudos