disk-model.ps1 1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# This powershell script is used to map drive letters to disk model numbers
# It is intended to be called by Runtime.getRuntime().exec(...)

Get-WmiObject Win32_DiskDrive | % {
  $disk = $_
  $partitions = "ASSOCIATORS OF " +
                "{Win32_DiskDrive.DeviceID='$($disk.DeviceID)'} " +
                "WHERE AssocClass = Win32_DiskDriveToDiskPartition"
  Get-WmiObject -Query $partitions | % {
    $partition = $_
    $drives = "ASSOCIATORS OF " +
              "{Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} " +
              "WHERE AssocClass = Win32_LogicalDiskToPartition"
    Get-WmiObject -Query $drives | % {
      New-Object -Type PSCustomObject -Property @{
16 17
        #Disk        = $disk.DeviceID
        #DiskSize    = $disk.Size
18
        DiskModel   = $disk.Model
19 20
        #Partition   = $partition.Name
        #RawSize     = $partition.Size
21
        DriveLetter = $_.DeviceID
22 23 24
        #VolumeName  = $_.VolumeName
        #Size        = $_.Size
        #FreeSpace   = $_.FreeSpace
25 26 27 28
      }
    }
  }
}