-1

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

whoami
  • 1,689
  • 3
  • 22
  • 45

2 Answers2

1

Use 'Get-PSDrive', e.g.:

Get-PSDrive -PSProvider 'FileSystem'

https://technet.microsoft.com/en-us/library/hh849796.aspx

mongjong
  • 479
  • 3
  • 6
  • so if I have C, D and E drive with C and D are the system boot partitions, this will return all C, D and E. Correct? How can I know which of these are system drives? – whoami Jul 19 '15 at 02:44
  • Yep it will return all partitions. If you need to filter further, you can use Get-WMIObject Win32_Volume which allows you to filter through more options. I don't have a computer with multiple partitions and things to test on at the moment but you can find more info here: https://msdn.microsoft.com/en-us/library/aa394515%28v=vs.85%29.aspx – mongjong Jul 19 '15 at 03:08
1

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.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328