PowerShell脚本中基于DeviceID的过滤

PowerShell脚本中基于DeviceID的过滤,powershell,Powershell,我正在尝试筛选出基于DeviceID的驱动器,但它失败了。当我尝试使用DriveType时,它工作正常 例如: (Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType = 3 ") 返回: DeviceID : C: DriveType : 3 ProviderName : FreeSpace : 181411000320 Size : 255791026176 VolumeName : 但

我正在尝试筛选出基于DeviceID的驱动器,但它失败了。当我尝试使用DriveType时,它工作正常

例如:

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

DeviceID     : C:
DriveType    : 3
ProviderName :
FreeSpace    : 181411000320
Size         : 255791026176
VolumeName   :
但是,如果我尝试使用DeviceID:

(Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID = C")
它返回:

(获取WmiObject-Class Win32_LogicalDisk-Filter“DeviceID=C”) 获取WmiObject:Invalid query“从Win32_LogicalDisk中选择*,其中 设备ID =C“在第1行字符:2处 +(获取WmiObject-Class Win32_LogicalDisk-Filter“DeviceID=C”) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CategoryInfo:InvalidArgument:(:)[Get WMIOObject],管理异常 +FullyQualifiedErrorId:GetWMIManagementException,Microsoft.PowerShell.C
ommands.GetWmiObjectCommand

这对我很有用:

(Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID='C:'")
看起来您需要在驱动器号周围使用引号,并包括冒号