Match a Windows Disk to a SAN-Attached Disk Using WWN and LUN ID

In this guide, we will explore multiple ways to retrieve LUN ID, WWN (World Wide Name), and Volume Name using PowerShell, DiskPart, and WMI.

Using PowerShell to Find LUN ID and Volume Name

PowerShell provides a quick way to match a disk with its LUN ID and associated Volume Name.

Get-Disk | ForEach-Object {
    $lun = ($_ | Select-Object -ExpandProperty LocationPath) -match "L(\d+)"
    $volume = Get-Volume -DiskNumber $_.Number -ErrorAction SilentlyContinue
    [PSCustomObject]@{
        DiskNumber   = $_.Number
        FriendlyName = $_.FriendlyName
        LunID        = if ($lun) { $matches[1] } else { "N/A" }
        VolumeName   = if ($volume) { $volume.FileSystemLabel } else { "No Volume" }
    }
}

Example Output:

DiskNumber FriendlyName    LunID VolumeName
---------- -------------   ---- -----------
0          Local Disk      N/A   OS
1          SAN Disk 1      3     Database
2          SAN Disk 2      7     Logs
3          SAN Disk 3      15    Backup

How It Works:

  • Extracts the LUN ID from the LocationPath property of Get-Disk.
  • Retrieves the volume label associated with the disk using Get-Volume.
  • Displays disks that have no assigned volumes as “No Volume”.

Using DiskPart

If you prefer a more command-line interactive approach, DiskPart can provide LUN ID information.

Steps to Find LUN ID using DiskPart:

  1. Open Command Prompt (cmd) as Administrator.
  2. Run diskpart and then execute the following commands:
diskpart
list disk
select disk X  # Replace X with the disk number
detail disk

Example Output:

DISKPART> detail disk
IBM 2145 SCSI Disk Device
Disk ID: 12345678
Type   : iSCSI
LUN ID : 7
Location Path : PCIROOT(0)#PCI(1F02)#SCSI(P02T00L07)

Key Information Found:

  • Disk ID
  • LUN ID (e.g., 7 in this case)
  • Location Path (useful for correlating with PowerShell output)

Using Get-WMIObject

Another effective way to retrieve LUN ID information is via Windows Management Instrumentation (WMI).

PowerShell Command:

Get-WMIObject -Namespace root\WMI -Class MSFC_DiskInformation | Select InstanceName, Lun

Example Output:

InstanceName                               Lun
----------------------------------------   ---
PCIROOT(0)#PCI(1F02)#SCSI(P01T00L03)       3
PCIROOT(0)#PCI(1F02)#SCSI(P02T00L07)       7

How It Helps:

  • Directly extracts LUN IDs.
  • Shows the InstanceName, which matches the LocationPath from Get-Disk.
  • Works well when diagnosing FC or iSCSI-attached disks.

🚀 Stay tuned for more storage and virtualization insights on vmanalyst.com!

(Visited 206 times, 1 visits today)

By Ash Thomas

Ash Thomas is a seasoned IT professional with extensive experience as a technical expert, complemented by a keen interest in blockchain technology.

Leave a Reply