Filtering get-psdrive to all Local Drives
Recently I needed to filter the return of get-psdrive to return all of my local hard drives. I didn't want to accidentally start operating on floppies, CDROM's and more importantly, network drives. There are a couple of ways to do this but I found the most straight forward is to combine the WMI data with get-psdrive.
E:\temp> get-wmiobject win32_volume | ? { $_.DriveType -eq 3 } | % { get-psdrive
$_.DriveLetter[0] }
Name Provider Root CurrentLocation
---- -------- ---- ---------------
C FileSystem C:\ ...nfig\PowerShell
E FileSystem E:\ temp
DriveType is a property of the Win32_Volume structure which enumerates the type of drive. The value 3 stands for Local Disk. Below is the full list of values.
0 - Unknown
1 - No Root Directory
2 - Removable Disk
3 - Local Disk
4 - Network Drive
5 - Compact Disk
6 - RAM Disk
Comments
Anonymous
December 06, 2007
PingBack from http://msdnrss.thecoderblogs.com/2007/12/06/filtering-get-psdrive-to-all-local-drives/Anonymous
December 09, 2007
Win32_Volume class is not available for Windows XP and earlier operating systems. We should use Win32_LogicalDisk class instead. The code will look like this: get-wmiobject Win32_LogicalDisk | ? {$.drivetype -eq 3} | % {get-psdrive $.deviceid[0]}