I'm using the following command to get disk info:
get-ciminstance -ClassName Win32_LogicalDisk
The problem is, it doesn't contain the MediaType
property (HDD, SSD, or in numerical form 4, 3 respectively).
I suppose I need to combine (associate) it with another command, like:
Get-PhysicalDisk
orGet-WmiObject -Class MSFT_PhysicalDisk -Namespace root\Microsoft\Windows\Storage
I'm calling these commands from Node.js, so I can run separate commands and combine the results afterwards. It doesn't have to be 1 command. I'm just not sure how to correlate them, because Powershell API are inconsistent:
This one returns numbers
(Get-WmiObject -Class MSFT_PhysicalDisk -Namespace root\Microsoft\Windows\Storage).DeviceID
And this one returns drive letters
(get-ciminstance -ClassName Win32_LogicalDisk).DeviceID
I found this code in another thread but I'm not sure how to add the MediaType
property in it:
Get-WmiObject Win32_DiskDrive | ForEach-Object {
$disk = $_
$partitions = "ASSOCIATORS OF " +
"{Win32_DiskDrive.DeviceID='$($disk.DeviceID)'} " +
"WHERE AssocClass = Win32_DiskDriveToDiskPartition"
Get-WmiObject -Query $partitions | ForEach-Object {
$partition = $_
$drives = "ASSOCIATORS OF " +
"{Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} " +
"WHERE AssocClass = Win32_LogicalDiskToPartition"
Get-WmiObject -Query $drives | ForEach-Object {
New-Object -Type PSCustomObject -Property @{
Disk = $disk.DeviceID
DiskSize = $disk.Size
DiskModel = $disk.Model
Partition = $partition.Name
RawSize = $partition.Size
DriveLetter = $_.DeviceID
VolumeName = $_.VolumeName
Size = $_.Size
FreeSpace = $_.FreeSpace
}
}
}
}