Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Uninstalling software that does not contain a method named 'Uninstall'

$
0
0

I'm still working on a script I had issues with a couple weeks ago. The purpose is to uninstall various software on remote machines. Here's the script:

$computers = Get-Content 'C:\computerlist.txt'
$program = 'java'
foreach ($computer in $computers) {
	Invoke-Command -ComputerName $computer -ScriptBlock {$app = Get-WmiObject -Class Win32_Product | Where-Object { 
	    $_.Name -match "$($using:program)"    }                        
	$app.Uninstall()
	} -ArgumentList $program
}

This works for software such as Flash and Shockwave, but when I try to use it with Java, I get the error:

Method invocation failed because [System.Object[]] doesn't contain a method named 'Uninstall'.+ CategoryInfo          : InvalidOperation: (Uninstall:String) [], RuntimeException+ FullyQualifiedErrorId : MethodNotFound+ PSComputerName        : Computername

I'm leaning towards the idea that Java was installed as an .exe so this '.Uninstall' method will not work? If I run

Get-WmiObject -Class Win32_Product

Java is in the list:

IdentifyingNumber : {26A24AE4-039D-4CA4-87B4-2F83217040FF}
Name              : Java 7 Update 40
Vendor            : Oracle
Version           : 7.0.400
Caption           : Java 7 Update 40



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>