错误:描述 = 无效查询 [英] ERROR: Description = Invalid query

查看:165
本文介绍了错误:描述 = 无效查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于组策略对象混乱,多台计算机在不该安装的情况下安装了 TightVNC.GPO 不见了,所以我不知道只是从那里删除软件.因此,我正在编写脚本以便从计算机列表中删除 PowerShell.

Because of a messed up group policy object, multiple computers have TightVNC installed when they shouldn't. The GPO is gone, so just removing the software from there isn't an option that I'm aware of. Therefore, I'm scripting things in order to remove PowerShell from a list of computers.

这是我的脚本:

if ($args.length -ne 1) {
    Write-Warning "Must pass computer name, ending script.";
    break
}

$pc = $args[0]

Write-Output "Scanning $pc for TightVNC...."
$prod = wmic /node:$pc product get name | where {$_ -match "TightVNC"}
if ($prod) {
    Write-Output "Found TightVNC, attempting uninstall...."
    wmic /node:$pc product where name="TightVNC" call uninstall
} else {
    Write-Warning "Could not find TightVNC on $pc."
}
Write-Output "Done."

现在,我的输出如下:

Scanning [computer] for TightVNC....
Found TightVNC, attempting uninstall....
ERROR:
Description = Invalid query
Done.

但是,如果我将第二个 wmic 行复制并粘贴到提升的命令提示符中并将 $pc 替换为 [computer],它就可以正常工作.我的 PowerShell 窗口已提升.

However, if I copy and paste the second wmic line into an elevated command prompt and replace $pc with [computer], it works just fine. My PowerShell window is elevated.

有谁知道为什么我的脚本会出现这种情况?我知道完成第一个 wmic 命令确实需要很长时间(> = 5 分钟),但它在实际工作的第二个命令窗口中也是如此.如果您对此有任何见解,我将不胜感激.

Does anyone know why my script would be having a fit about this? I know that it does take quite a long time for the first wmic command to complete (>=5 minutes), but it does as well in the second command window where it actually works. I'd appreciate any insight into this.

注意:我使用 wmic 是因为这里的计算机没有正确配置用于远程 PowerShell 访问.它在我要做的事情清单上.

NOTE: I am using wmic because the computers here aren't properly configured for remote PowerShell access. It's on my list of things to do.

推荐答案

您正在运行 PowerShell 的字符串解析.试试这个:

You're running afoul of PowerShell's string parsing. Try this instead:

wmic /node:$pc product where name=`"TightVNC`" call uninstall

注意,对于使用 PowerShell V3 的用户,您可以使用:

Note, for those on PowerShell V3, you can use:

wmic /node:$pc --% product where name="TightVNC" call uninstall

这篇关于错误:描述 = 无效查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆