ERROR: Description = Invalid query

11,865

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
Share:
11,865
Skyline969
Author by

Skyline969

Updated on June 12, 2022

Comments

  • Skyline969
    Skyline969 almost 2 years

    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.