2
votes

In PowerShell I'm trying to get the drive letter that an ISCSI target is mapped to. I'm using the following to get the ISCSI initiator name.

Get-IscsiTarget | ? {$_.IsConnected -eq $True} | Select -ExpandProperty NodeAddress

I have tried using Get-Disk | Select * and Get-PSDrive | Select * but these cmdlets do not seem to have any fields that I can link a target to, to obtain its drive letter.

1
An iSCSI target may present more than one logical unit, such that you may have more than one drive. Check out this other question that takes a different approach: look at the list of drives both before and after bringing the iSCSI session up: stackoverflow.com/questions/36286366/…Mike Andrews
@gubblebozer the link you have given me isn't a diffrent question, it links back to is this question?Richard
Ugh... cut and paste fail. This is the question I had intended: stackoverflow.com/questions/30957901/…Mike Andrews

1 Answers

1
votes

As long as you have one active partition (not including reserved) per ISCSI target, you can use the following to match an ISCSI address to its corresponding drive letter.

foreach ($disk in (Get-Disk | ?{$_.BusType -Eq "iSCSI"})){

    $DriveLetter = ($disk | Get-Partition | ?{$_.Type -eq "Basic"}).DriveLetter
    $ISCSI = $disk | Get-IscsiSession

    [pscustomobject]@{
        DiskNumber=$disk.Number; 
        DriveLetter=$DriveLetter; 
        InitiatorNodeAddress=$ISCSI.InitiatorNodeAddress;
        InitiatorIP=$ISCSI.InitiatorPortalAddress;
        Size=$disk.Size;
    }  
}

This will check all connected ISCSI disks and get their corresponding drive letter, then it will put all the information into a customer PowerShell object and return it.