1

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.