You need to enable JavaScript to run this app. 如何通过CMD执行带引号的PowerShell命令 WMI查询设备属性报错求解
优惠活动
大模型
产品
解决方案
定价
更多

如何通过CMD执行带引号的PowerShell命令 WMI查询设备属性报错求解

CMD执行PowerShell命令异常修复方案

错误原因

  1. 引号嵌套未正确转义:CMD中使用powershell -command执行命令时,若用双引号包裹整段PowerShell代码,代码内部的双引号需要做转义处理,否则CMD会提前截断命令,导致语法解析错误。
  2. 命令逻辑不完整:你编写的CMD执行命令仅包含了前半段WMI对象查询逻辑,遗漏了获取设备属性、筛选输出字段的后半段代码,即使引号正确也无法得到目标结果。

修复后的可执行命令

提供两种兼容性良好的写法任选其一即可:

方案1:使用反斜杠转义内部双引号

powershell -command "(Get-WmiObject -Class win32_pnpEntity -Filter 'Name like \"ACPI Thermal Zone\"')[1].GetDeviceProperties().DeviceProperties | Select-Object -Property keyName, data"

方案2:使用双引号重复转义(遵循CMD原生转义规则)

powershell -command "(Get-WmiObject -Class win32_pnpEntity -Filter ""Name like 'ACPI Thermal Zone'"")[1].GetDeviceProperties().DeviceProperties | Select-Object -Property keyName, data"

内容的提问来源于stack exchange,提问作者Michael Gabbay

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.12 10:36:03