powershell - 为什么在尝试卸载时 WMIC 给出无效查询?

标签 powershell windows-10 wmic

我尝试通过 PowerShell 卸载常规程序,但我尝试放入 name="program name" 部分的所有内容似乎都失败了。

我关注了this guide here关于如何做到这一点。

我尝试删除 Google Chrome 作为我的测试示例。它实际上并不是我想要删除的,只是一个我可以轻松快速地重新安装的测试目标。

我首先在另一台装有 Google Chrome 的机器上进行了测试,但没有出现在这个列表中。也出现了这个错误。但现在我在我的主机上进行了测试,Google Chrome 确实出现在列表中。

PS C:\WINDOWS\system32> wmic product get name                                                                           Name
Microsoft Visual C++ 2010  x64 Redistributable - 10.0.40219
Microsoft Visual C++ 2010  x86 Redistributable - 10.0.40219
Microsoft Visual Studio 2010 Tools for Office Runtime (x64)
Google Chrome
Google Update Helper
Microsoft SQL Server 2008 Native Client

PS C:\WINDOWS\system32> wmic product where name="Google Chrome" call uninstall
ERROR:
Description = Invalid query

一些不相关的产品获取名称条目已被删除,以保持列表简短。

我希望 WMIC 卸载该程序,但我收到了上面发现的错误。

最佳答案

WMIC 命令需要引号内的过滤器:wmic Product where "name='Google Chrome'"

Powershell 还公开了具有更清晰语法的 Get-WMIObject cmdlet(别名 gwmi):

$chrome = gwmi win32_product -filter "name='Google Chrome'"
$chrome.Uninstall

关于powershell - 为什么在尝试卸载时 WMIC 给出无效查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57151712/

相关文章:

powershell - 如何使用 PowerShell 替换文件中的一行?

powershell - 重命名多个子文件夹中的项目

windows - 要求用户输入(/P)时批处理脚本中的语法错误

windows - 如何在 Windows PE 脚本中使用 `wmic`?

windows - 使用 .bat 文件从 Windows 启动中删除程序

xml - 如何使用 PowerShell 更改 XML 元素属性的值?

powershell - Powershell有时输出目录路径的方式有所不同

c++ - 子系统:native中的异常处理

c++ - 如何使用 WinAPI 重启 Windows 8/10 并进入高级启动选项?

c++ - 抛出异常但未在 C++ 程序中捕获