我正在尝试根据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")
它返回:
(Get-WmiObject -Class Win32_LogicalDisk -Filter" DeviceID = C") Get-WmiObject:查询无效"从Win32_LogicalDisk中选择* 设备编号 = C"在行:1 char:2 +(Get-WmiObject -Class Win32_LogicalDisk -Filter" DeviceID = C") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~ + CategoryInfo:InvalidArgument:(:) [Get-WmiObject],Management Exception + FullyQualifiedErrorId:GetWMIManagementException,Microsoft.PowerShell.C
ommands.GetWmiObjectCommand
答案 0 :(得分:1)
这对我有用:
(Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID='C:'")
看起来你需要在驱动器号周围使用引号并包含冒号。