How to get list of drive letters in Powershell 2.0

Question:

I’m trying to get a list of drive letters in a drop-down menu. I’m currently using the code below and it works just fine in Windows 10, but doesn’t work at all in Windows 7.

In Win 7 I tried adjusting the code to this…

But now it shows “@DeviceID=C:}”, “@DeviceID=D:}”, etc. in Win 7 and 10 for each drive letter. I need to just show “C:”, “D:”, etc.

Thanks!

Answer:


This will return all drives mapped in the current session. The Name property contains the drive letter.

To capture just drive letters:

Source:

How to get list of drive letters in Powershell 2.0 by licensed under CC BY-SA | With most appropriate answer!

Tested working in PSv2:

Source:

How to get list of drive letters in Powershell 2.0 by licensed under CC BY-SA | With most appropriate answer!

Source:

How to get list of drive letters in Powershell 2.0 by licensed under CC BY-SA | With most appropriate answer!

Tested working in PSv2:

Source:

How to get list of drive letters in Powershell 2.0 by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply