Get Lun Number and disk letter using powershell

ACDBA 421 Reputation points
2022-12-16T11:01:42.863+00:00

Hi All,

Is there a way we can find out LUN number and Disk letter using a PowerShell script?

271365-capture.jpg

I tried Get-Disk,Get-Volume etc.but there seems to be nothing in common.

Thanks,
ACDBA

Windows for business Windows Client for IT Pros Devices and deployment Other
Windows for business Windows Server User experience PowerShell
Windows for business Windows Server User experience Other
0 comments No comments
{count} votes

Accepted answer
  1. Limitless Technology 44,751 Reputation points
    2022-12-19T09:29:26.793+00:00

    Hello there,

    The following script can be used in PowerShell to get the Serial Number for either the physical or virtualized host:

    Get the list of all available drives

    $d = (Get-PSDrive).Name -match '^[a-z]$'
    For each of the drivers, extract the serial number

    get-partition -DriveLetter $i | get-disk

    Complete working code

    $d = (Get-PSDrive).Name -match '^[a-z]$'
    Foreach ($i in $d)
    {
    Write-Host $i". " -nonewline
    get-partition -DriveLetter $i | get-disk
    }

    Similar discussion here https://social.technet.microsoft.com/Forums/office/en-US/5b4a7b5b-b1e1-4296-a8c4-762bd2eeef83/powershell-script-to-get-disk-uniqueid-and-drive-letter?forum=winserverpowershell

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer–


6 additional answers

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2022-12-16T15:41:58.16+00:00

    Yes, you can use the PowerShell cmdlet Get-Disk to list the disks on a system, and Get-Partition to list the partitions on a disk. You can then use the Number property of the Partition object to get the LUN number and the DriveLetter property to get the drive letter.

    Here is an example of how you can use these cmdlets to get the LUN number and drive letter for all disks and partitions on a system:

    $disks = Get-Disk  
    foreach ($disk in $disks)  
    {  
        $partitions = Get-Partition -DiskNumber $disk.Number  
        foreach ($partition in $partitions)  
        {  
            Write-Output "LUN Number: $($partition.Number)"  
            Write-Output "Drive Letter: $($partition.DriveLetter)"  
        }  
    }  
      
    

    This will output the LUN number and drive letter for each partition on each disk. You can also use the -FriendlyName and -Description properties of the Disk object to get more information about the disks.

    1 person found this answer helpful.

  2. ACDBA 421 Reputation points
    2022-12-16T20:25:02.66+00:00

    Hi Rich,

    Thanks for your time. But i am unable to get the results. LUN value is empty. This is an azure IAAS VM.

    ![271370-capture.jpg][2] [2]: /api/attachments/271370-capture.jpg?platform=QnA

    Also i dont get results for $partition.Number..But $partition.PartitionNumber.But it seems to be wrong.

    I am not sure how the disks are configured.

    Get-Disk

    Number Friendly Name Serial Number HealthStatus OperationalStatus Total Size Partition
    Style


    0 Msft Virtual Disk Healthy Online 120 GB GPT
    2 Msft Virtual Disk Healthy Online 15 GB GPT
    1 Msft Virtual Disk Healthy Online 300 GB GPT

    Get-Partition

    DiskPath: \?\scsi#disk&ven_msft&prod_virtual_disk#000000#{1234567890}

    PartitionNumber DriveLetter Offset Size Type



    1 1048576 450 MB Recovery
    2 472907776 99 MB System
    3 576716800 16 MB Reserved
    4 C 593494016 119.45 GB Basic

    DiskPath: \?\scsi#disk&ven_msft&prod_virtual_disk#000001

    PartitionNumber DriveLetter Offset Size Type



    1 17408 32 MB Reserved
    2 Y 34603008 14.97 GB Basic

    DiskPath: \?\scsi#disk&ven_msft&prod_virtual_disk#

    PartitionNumber DriveLetter Offset Size Type



    1 17408 128 MB Reserved
    2 D 135266304 299.87 GB Basic


  3. ACDBA 421 Reputation points
    2022-12-16T20:53:23.013+00:00

    I am trying to corelate LUN's from the azure portal and LUN value inside the server.

    0 comments No comments

  4. Rich Matheisen 47,901 Reputation points
    2022-12-17T03:40:59.737+00:00

    Does the function Get-DiskScsiLun at this link help? powershell-function-to-get-disk-scsi-lun-number

    The old "diskpart" tool can also get the LUN ID using these to get the information

    select disk X  
    detail disk X  
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.