Search code examples
powershell-3.0disk-partitioning

list of system drives


I have a system with multiple boot partitions(C and D). On this system, I have some other volumes that are for data. Is there anyway I can retrieve all system partitions using power shell? I have googled for solution but couldn't find much help. Any ideas or starting point could be a big help


Solution

  • You could enumerate volumes using Get-WmiObject -Class Win32_Volume. However, the BootVolume property will only indicate the current boot volume. System folders of other Windows installations are not recognized.

    You could check for the presence of a Windows folder or kernel file on other partitions:

    Get-WmiObject -Class Win32_Volume | ? {
      $_.DriveLetter -and
      (Test-Path -LiteralPath (Join-Path $_.Name 'Windows\system32\ntoskrnl.exe'))
    } | select -Expand DriveLetter
    

    Beware, though, that this check requires the other volume(s) to actually have a drive letter assigned to them, and is easily fooled if someone creates a spurious file \Windows\system32\ntoskrnl.exe on a drive.