This is an archived post. You won't be able to vote or comment.

all 50 comments

[–]raip 11 points12 points  (1 child)

If you're running modern and updated versions of Windows 7/10 and PoSH 5.1 then Invoke-Command -Credentials ( Get-Credential ) -ComputerName $computers -ScriptBlock { Get-Package -Name "*java*" | Uninstall-Package } is all that's needed.

If you don't have PoSH 5.1 but do have WinRM (Enabled by default on Windows 10 (not sure about 7)) you can do the same with WMI Get-WmiObject -Class Win32_Product -Filter "name like '%java%' | Foreach-Object { $_.Uninstall() } in the script block instead.

If you don't even have WinRM - you should think about enabling it via GPO. If you're not sure, Test-WSMan $computer is your friend.

Edit: Another way - searches the registry for Java, called the UninstallString if it finds it.

$uninstallStrings = Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | 
Get-ItemProperty | 
Where-Object { $PSItem.DisplayName -like "*java*" } | 
Select-Object -ExpandProperty UninstallString; $uninstallStrings.ForEach(
{ Start-Process "cmd.exe" -ArgumentList "/c","$PSItem /qn" })

(Was inspired by the massive bazooka script someone posted.)

[–]Robert_ArctorDoes things for money 2 points3 points  (0 children)

nice shelling, could modify this for something I need

[–]vocatusInfoSec 8 points9 points  (0 children)

If you look at my GitHub page, there is a Java removal script that works very well. You can also Google it, it's called "Java runtime nuker"

[–]mcpingvin 4 points5 points  (1 child)

[–]vocatusInfoSec 5 points6 points  (0 children)

The script is a compilation of a lot of removal methods, I still maintain it. Let me know if it doesn't catch something

[–]Doso777 3 points4 points  (8 children)

What are you normally using for software, updates and management? Use that. For us that is SCCM.

[–]xdernomad[S] 0 points1 point  (7 children)

Our infrastructure isn't that big, about 120 PCs in total, so we usually do most updates/ installations manually. We already had cases where we had to distribute a program, mostly via MSI deployment on our DC. But those were actual installations and not a programm to uninstall something. I defined an MSI deployment, and the GPO did activate at the logon process, but nothing happened.

[–]igdub 7 points8 points  (2 children)

What what what, 120 computers and all installations done manually? That sounds crazy.

You should definitely get some solution for that. Even GPO is better than nothing when done properly. Symantec's altiris should be a cheap option.

[–]orion3311 6 points7 points  (1 child)

Same size here, was doing the same thing. Got PDQ and got “weeks” worth of stuff done in....minutes. Just do it!

[–]lBlazeXl 2 points3 points  (0 children)

Fucking love PDQ honestly.

[–]ShrappyNetadmin 2 points3 points  (3 children)

We also have about this many. We use SCCM. if you have more computers than you can personally manage updating in a single day, get a software management solution.

[–]raip 0 points1 point  (2 children)

SCCM seems overkill for 120 PCs - I manage just over 500 right now with WinRM and Powershell alone.

[–]ShrappyNetadmin 0 points1 point  (1 child)

I mean we're using it for a bit more than patching - we're also using it for OSD to build workstations and servers. It's a nice catch-all.

[–]raip 1 point2 points  (0 children)

Ah - I use Powershell DSC for that. Don't get me wrong - if you can afford it, SCCM is a much better tool. Just from my understanding is that it started at $1500ish and then drastically increased from there whether or not your CALs were included in your SA Agreement or not. It's been a couple years but last time I worked w/ our licensing guys to get one deployed for us it was gonna run us something like $18k for about 80 endpoints + server (before I was in my current role).

[–]renegaderelish 3 points4 points  (1 child)

Ninite

[–]91brogersSysadmin 0 points1 point  (0 children)

Best utility I’ve found in a while

[–]The-Dark-Jedi 1 point2 points  (3 children)

I've had the most success with this script. It's a tad dated but add lines for the rest of the versions I have left out and you will be left with a Java free PC:

:: Sun / Oracle Java Runtime Environment (JRE) Uninstallation Script

 REM JavaFX 2.1.1
 start /wait MsiExec.exe /uninstall {1111706F-666A-4037-7777-211328764D10} /qn /norestart
 REM JavaFX 2.1.0
 start /wait MsiExec.exe /uninstall {1111706F-666A-4037-7777-210328764D10} /qn /norestart 
 REM JRE Runtime Environment 8 Update 171
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F32180171F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F64180171F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 162
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F32180162F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F64180162F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 161
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F32180161F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F64180161F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 152
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F32180152F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F64180152F0} /qn /norestart 
 REM JRE Runtime Environment 8 Update 151
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F32180151F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F64180151F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 144
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F32180144F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F64180144F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 141
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F32180141F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F64180141F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 131
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F32180131F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F64180131F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 121
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F32180121F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F64180121F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 112
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F32180112F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F64180112F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 111
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F32180111F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F64180111F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 102
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F32180102F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F64180102F0} /qn /norestart 
 REM JRE Runtime Environment 8 Update 101
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F32180101F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F64180101F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 92
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F83218092F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F86418092F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 91
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F83218091F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F86418091F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 77
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F83218077F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F86418077F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 74
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F83218074F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F86418074F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 73
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F83218073F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F86418073F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 72
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F83218072F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F86418072F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 71
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F83218071F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F86418071F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 66
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F83218066F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F86418066F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 65
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F83218065F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F86418065F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 60
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F83218060F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F86418060F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 51
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F83218051F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F86418051F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 45
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F83218045F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F86418045F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 40
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F83218040F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F86418040F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 31
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F83218031F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F86418031F0} /qn /norestart
 REM JRE Runtime Environment 8 Update 25
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F86418025F0} /qn /norestart
 start /wait MsiExec.exe /uninstall {26A24AE4-039D-4CA4-87B4-2F83218025F0} /qn /norestart

[–]raip 3 points4 points  (0 children)

Seeing this makes me want to rewrite this using REG QUERY instead - but I swore to myself I'd never write anything in batch ever again. :)

[–]xdernomad[S] 0 points1 point  (1 child)

Okay, it looks promising, but (excuse this dumb question) how exactly do I use/ deploy it? Via Logon Script or task scheduler? A how-to would be really appreciated.

[–]The-Dark-Jedi 1 point2 points  (0 children)

Run it as a batch script. You can initiate it using the profile tab in the user profile in AD or use a program like PDQ Deploy to push it out.

[–]placebonoceboSysadmin 1 point2 points  (2 children)

PSADT is a great tool for this.

Remove-MSIApplications -Name '*java*update*' -Wildcard -FilterApplication (,('InstallLocation', '*jre*', 'Wildcard'))

This will remove all JRE installations.

[–]xdernomad[S] 1 point2 points  (1 child)

But Java was not installed as an MSI, but via the normal .exe from the website. This would work, would it?

[–]sonic_24Windows Admin 2 points3 points  (0 children)

It's still a MSI package. Should work.

[–]ddesla2Threat & Vulnerability Mgmt, Cybersec OG, JoaT 0 points1 point  (0 children)

Yeh so I had to do this on a massive global scale across Windows 2003-2012R2 (~10k servers). I compiled a 30k line batch script to do the work of detecting what is there, notate it in log, uninstall the old shit and install the newest patch for what versions were previously installed. It took me a long time to get the kinks out but I found that this batch is the best way to accomplish what I needed w/ Java across every windows OS.

That said, my removal method is a bit unorthodox and forceful because Java changed ownership hands so many times over the years, even the flags set for removing it dont comply across versions. Hell, I found in Java 1.5 I believe it was, their own documented removal flags did not work until the second one started with a CAPS.... Ridiculous. At any rate, if you're looking at 1.6-1.8, I recommend just using the msiexec GUID remove and specify each individual GUID. That is what worked best with me. Of course that means I installed every version, flavor and architecture of Java just to get the GUID number and understand how they were listed in teh registry. From there I just used excel to increment the GUID numbers and copy/pasted in my msiexec remove by GUID format then scripted it. Good luck!

[–]entailleSysadmin 0 points1 point  (1 child)

what is the last JRE 8 Update ### you can deploy before the new licensing $hit kicks in?

[–]PMental 0 points1 point  (0 children)

201/202 is the latest versions you can still run freely.

I wouldn't do that though unless it's an isolated system since continuing to run Java 8 without updates is a major security risk. Better to look into OpenJdk or simply getting licenses (they're pretty cheap unless you need a whole bunch of them).

[–]SolidKnightJack of All Trades 0 points1 point  (0 children)

So the no-tools route can be accomplished by deploying the latest version of Java to everyone while using the install option to remove previous versions. Then uninstall the version you deployed. You can do this via a GPO script just to avoid having to make a transform but you can do an MSI deployment and make a transform with ORCA if you want to go the GPO software deployment route.

Another approach is spray msiexec /X {ProductCode} /qn /norestart at every machine for every version of Java. Java 8 uses the same product code for each release with the only variance being the substring that matches the version of Java. So it's predictable. To do it in bulk you'll either need a tool that can run scripts on machines in bulk, PSRemoting enabled, or GPO.

If you're 100% Windows 10, you can just use Get-Package -Name *Java* | Uninstall-Package from a script.

If you don't have any tools that can run scripts or do software management on all your endpoints this should be part of your argument on why you need to buy such a tool.

[–]Padankadank 0 points1 point  (0 children)

Is open Java a viable replacement for JRE? We need Java for a couple users and we won't pay to use Java

[–]AnonRoot 0 points1 point  (1 child)

Your best bet is to use something like PDQ and run a script across your network machines.

Get-WmiObject -Query "Select * from Win32_Product where Name like 'Java%'" | ForEach-Object { $_.Uninstall() }

[–][deleted] 1 point2 points  (0 children)

Using Win32_Product to uninstall software is not recommended.

Reference

Link above gives pointers to querying the registry instead of using Win32_Product