Getting the serial number for a PhysicalDrive

I don’t find a solution to get the required info in a single script, but this way will help to find the serial number for the physicaldrive.

  1. run below wmic command for command prompt to get the disk number and serial number
    • WMIC disk drive get name, serial number
  2. run below PowerShell script to get disk number and size. by comparing the size of a disk in file explorer we can get the drive name, then get the serial number from the first step.
    • Function Main {
    • $diskdrives = get-wmiobject Win32_DiskDrive | sort Index
    • $colSize = @{Name=’Size’;Expression={Get-HRSize $_.Size}}
    • foreach ( $disk in $diskdrives ) {
    • $scsi_details = ‘SCSI ‘ + $disk.SCSIBus + ‘:’ +
    • $disk.SCSILogicalUnit + ‘:’ +
    • $disk.SCSIPort + ‘:’ +
    • $disk.SCSITargetID
    • write $( ‘Disk ‘ + $disk.Index + ‘ – ‘ + $scsi_details +
    • ‘ – ‘ + ( Get-HRSize $disk.size) )
    • $part_query = ‘ASSOCIATORS OF {Win32_DiskDrive.DeviceID=”‘ +
    • $disk.DeviceID.replace(‘\’,’\’) +
    • ‘”} WHERE AssocClass=Win32_DiskDriveToDiskPartition’
    • $partitions = @( get-wmiobject -query $part_query |
    • sort StartingOffset )
    • foreach ($partition in $partitions) {
    • $vol_query = ‘ASSOCIATORS OF {Win32_DiskPartition.DeviceID=”‘ +
    • $partition.DeviceID +
    • ‘”} WHERE AssocClass=Win32_LogicalDiskToPartition’
    • $volumes = @(get-wmiobject -query $vol_query)
    • write $( ‘ Partition ‘ + $partition.Index + ‘ ‘ +
    • ( Get-HRSize $partition.Size) + ‘ ‘ +
    • $partition.Type
    • )
    • }
    • function Get-HRSize {
    • [CmdletBinding()]
    • param(
    • [Parameter(Mandatory=$True, ValueFromPipeline=$True)]
    • [INT64] $bytes
    • )
    • process {
    • if ( $bytes -gt 1pb ) { “{0:N2} PB” -f ($bytes / 1pb) }
    • elseif ( $bytes -gt 1tb ) { “{0:N2} TB” -f ($bytes / 1tb) }
    • elseif ( $bytes -gt 1gb ) { “{0:N2} GB” -f ($bytes / 1gb) }
    • elseif ( $bytes -gt 1mb ) { “{0:N2} MB” -f ($bytes / 1mb) }
    • elseif ( $bytes -gt 1kb ) { “{0:N2} KB” -f ($bytes / 1kb) }
    • else { “{0:N} Bytes” -f $bytes }
    • }
    • }
    • Main