Get-WmiObject -ComputerName $ip -Credential $credential -Class Win32_logicaldisk
This gets me disks as I see them in "My computer", eg. C:, D:, E: Now how I get corresponding underlying physical disks ?
If I run following command
Get-WmiObject -ComputerName $ip -Credential $credential -Class win32_diskdrive
I get disk 0, disk 1, disk 2
So how to find out which logical disk is on which physical disk ?
Another question is how to find out volume number ? If I run diskpart and executes "list volume" I get the following output
Volume ### Ltr Label Fs Type Size Status Info
---------- --- ----------- ----- ---------- ------- --------- --------
Volume 2 C NTFS Partition 59 GB Healthy Boot
...
How can I find out that logical disk C: is Volume 2 ?
best regards, Primoz.
Try this
Get-WMIObject Win32_LogicalDisk | Foreach-Object {
Get-WmiObject -Query "Associators of {Win32_LogicalDisk.DeviceID='$($_.DeviceID)'} WHERE ResultRole=Antecedent"
} | Format-Table
This gives you the related instances of WIn32_logicalDisk where Win32_LogicalDisk is the dependent entity in the relationship. So, you get the Win32_DiskDrive instances.
Here is Chad Miller's answer modified to work with PowerShell Core and with proper quotes and apostrophes so that it actually works on Linux/Windows and regardless of term settings (i.e., UTF-8 or not):
param ($ComputerName)
$partitions = Get-CimInstance -ComputerName $ComputerName Win32_DiskPartition
$partitions |
foreach `
{
Get-CimInstance -ComputerName $ComputerName `
-Query "ASSOCIATORS OF `
{Win32_DiskPartition.DeviceID='$($_.DeviceID)'} `
WHERE AssocClass=Win32_LogicalDiskToPartition" |
Add-Member -MemberType NoteProperty PartitionName $_.Name -PassThru |
Add-Member -MemberType NoteProperty Block $_.BlockSize -PassThru |
Add-Member -MemberType NoteProperty StartingOffset $_.StartingOffset -PassThru |
Add-Member -MemberType NoteProperty StartSector ($_.StartingOffset/$_.BlockSize) `
-PassThru
} |
Select SystemName, Name, PartitionName, Block, StartingOffset, StartSector |
Sort-Object -Property Name # Sort by Drive letter to improve quality of life
# Select code above starting to the left of the hash in this comment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With