0

Windows powershell command to uninstall all versions of Java except a specific version. This command should work in windows 7 & above.

The following command uninstalls all versions. How do I modify the following in such a way that a specific version 8.0.770.3 does not uninstall.

gwmi Win32_Product -filter "name like 'Java%' AND vendor like 'Oracle%' AND (version like '[78].%' OR version like '1.[78].%')" | % { $_.Uninstall() }

2 Answers 2

1

Change the filtering of version.

gwmi Win32_Product -filter "name like 'Java%' AND vendor like 'Oracle%' AND
not version = '8.0.770.3'" | % { $_.Uninstall() }
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks much Martin! this did the trick.. can i run the same with command prompt ?. It would be very helpful if it works via cmd. powershell.exe "gwmi Win32_Product -filter "name like 'Java%' AND vendor like 'Oracle%' AND not version = '8.0.770.3'" | % { $_.Uninstall() }"
But you need to escape the ".. like this: powershell.exe "gwmi Win32_Product -filter \"name like 'Java%' AND vendor like 'Oracle%' AND not version = '8.0.770.3'\" | % { $_.Uninstall() }" .
0

simplest powershell script

gwmi Win32_Product -filter "name like 'Java%'" | % { $_.Uninstall() }

1 Comment

Does this add value to Martin's accepted 2016 answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.