Take the 2-minute tour ×

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

$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....
Description = Invalid query

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.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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|improve this answer
That worked! Now I've got another issue, but it's not related to the script (which works just fine now). Thanks for the help. –  Skyline969 Jan 3 '13 at 14:17
add comment

Your Answer


