【问题标题】:Filtering based on DeviceID in PowerShell Script在 PowerShell 脚本中基于 DeviceID 进行过滤
【发布时间】:2018-06-13 22:50:52
【问题描述】:

我正在尝试根据 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 字符:2 + (Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID = C") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-WmiObject],管理异常 + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.C
ommands.GetWmiObjectCommand

【问题讨论】:

    标签: powershell


    【解决方案1】:

    这对我有用:

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

    看起来您需要在驱动器号周围使用引号并包含冒号。

    【讨论】:

      猜你喜欢
      • 2023-03-26
      • 2021-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-17
      • 2022-12-06
      • 2021-10-30
      相关资源
      最近更新 更多