Using PowerShell I select one Volume querying by name and filesystem with this line:

$volume = Get-Disk | Get-Partition | Get-Volume | Where { $_.FileSystemType -eq 'NTFS' -and $_.FileSystemLabel -eq 'MainOS' } |  Select -index 0

But after that, I want to know in which Disk is this Volume located.

I thought that the Volume object would have a DiskId property, but it doesn't.

Then, how can I know the DiskId of the Volume?

  • You might be making your life more difficult by trying to do all of that in a single pipeline. You almost certainly have the information you need from the Get-Disk,or Get-Partition results, but you won't be easily able access those results after the Get-Volume. – Zoredache Jun 5 '18 at 21:22
  • Should I use nested foreachs then? – SuperJMN Jun 5 '18 at 21:34
  • Are you trying to only do this at athe prompt or are you writing a script that you plan to save to a file. – EBGreen Jun 5 '18 at 21:57
  • I'm trying to create a Volume inside the same Disk where the "MainOS" Volume resides. I use this volume to identify the correct disk. – SuperJMN Jun 6 '18 at 7:31
  • I'll ask again...Are you trying to do this at the powershell prompt? Or are you doing it in a script? – EBGreen Jun 6 '18 at 12:16

Alright, well here is a way to do it. I only have one drive to look at right now but this should point you in the right direction:

#Get the Volume labeled MainOS with a File type of NTFS
$volume = Get-Volume -FileSystemLabel | Where-Object{$_.FileSystemType -eq 'NTFS'}
# Use the volume's driveletter to get the partition
$partition = Get-Partition -DriveLetter $volume.DriveLetter
# use the partition's disknumber to get the disk
$disk = Get-Disk -Number $partition.DiskNumber
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.