Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: Description = Invalid query

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.

This is my script:

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."

Now, my output is as follows:

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

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.

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.

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.

like image 636
Skyline969 Avatar asked Jan 02 '13 22:01

Skyline969


Video Answer


1 Answers

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

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

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

wmic /node:$pc --% product where name="TightVNC" call uninstall
like image 123
Keith Hill Avatar answered Sep 20 '22 21:09

Keith Hill