2013-01-02 566 views
4

由于组策略对象混乱,多台计算机都应安装TightVNC。 GPO不见了,所以从那里删除软件并不是我所知道的选项。因此,我正在编写脚本以便从计算机列表中删除PowerShell。错误:描述=无效的查询

这是我的脚本:

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线粘贴到提升的命令提示符并替换$电脑与[电脑],它工作得很好。我的PowerShell窗口被提升。

有谁知道为什么我的脚本会适合这个?我知道第一个wmic命令需要很长时间才能完成(> = 5分钟),但是它在第二个命令窗口中也能正常工作。我非常感谢这方面的任何见解。

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

回答

6

你正在运行PowerShell的字符串解析。试试这个:

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

注意,对于那些对PowerShell的V3,你可以使用:

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

这工作!现在我又遇到了另一个问题,但与脚本无关(现在工作得很好)。谢谢您的帮助。 – Skyline969