1
votes

I am trying to filter out drives based on DeviceID, however its failing. When I try using DriveType its working fine.

For Example:

(Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType = 3 ")

Returns:

DeviceID     : C:
DriveType    : 3
ProviderName :
FreeSpace    : 181411000320
Size         : 255791026176
VolumeName   :

However if I try using DeviceID:

(Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID = C")

It returns:

(Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID = C") Get-WmiObject : Invalid query "select * from Win32_LogicalDisk where DeviceID = C" At line:1 char:2 + (Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID = C") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-WmiObject], Management Exception + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.C
ommands.GetWmiObjectCommand

1

1 Answers

1
votes

This works for me:

(Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID='C:'")

Looks like you need to use quote marks around the drive letter and include the colon.