Uninstall-Java – Powershell Script and Module 1.0 release

Posted: August 22, 2014 in Automation, Java, powershell, Windows

Today I’ve released what I’m considering a 1.0 release of the Uninstall-Java Powershell script and Module code.

I’ve performed some testing of both the script and module on Windows 7, 8 and 8.1 and the code seems to be stable and clean. As always I highly recommend testing in your environment.

This project started after the furor over major security bugs in Java and now has developed into a full project aimed at simplifying the management of Java versions in large environments by ensuring wither java is not installed or only the approved version is deployed. Previous articles (here and here) I wrote go into some of the detail and the development progress is tracked in some of the comments.

In the process I started my first Codeplex project as a way to distribute the code. There was a bit of a learning curve in using Codeplex and Git and along with some character encoding issues led to code being available which didn’t run when downloaded from Codeplex. These have been fixed (sorry to anyone who tried to use the damaged code) and is now available from the Codeplex project download page at https://poshuninstalljava.codeplex.com.

I’d appreciate any feedback or results of any testing that any of you do, either on the Codeplex project site or as a comment against this post. Documentation should be sufficient for anyone with basic Powershell knowledge and as time allows I’ll try and improve both the documentation in Codeplex and within the code itself.

Advertisements
Comments
  1. […] Uninstall-Java – Powershell Script and Module 1.0 release […]

  2. […] Uninstall-Java – Powershell Script and Module 1.0 release […]

  3. BryanP says:

    Hi. I’ve been playing with this and I have a question. First, I am NOT any kind of powershell expert. First I installed the following versions of Java on a test PC

    J2SE Runtime Environment 5.0 Update 11
    Java(TM) 6 Update 41
    Java 7 Update 60 (64-bit)
    Java 7 Update 71
    Java 8 Update 25

    I deployed your script via SCCM against the test PC with the following options:

    powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File .\uninstall-java.ps1 -KeepVersion “7.0.710”

    It removed Java 5, Java 6, and Java 7 Update 60 (64-bit). It left Java 7 Update 71 alone, as I intended. However, it also left Java 8 in place. Will the script not also remove Java 8?

    • Hi Bryan. I havent yet tested it with Java 8 so I’m not sure. Wouldn’t be surprised if Oracle had changed the intsall and uninstall process somehow. When I have a chance I’ll bring up a test machine and investigate.

  4. BryanP says:

    Of course 10 minutes after I left my question the light came on. Your script (which works very well), checks for Vendor=’Sun Microsystems, Inc.’ or Vendor=’Oracle’. Java 8 has a Vendor name of Oracle Corporation. I added a check for Vendor=’Oracle Corporation’ and all is well.

  5. Kevin P says:

    Hey, Thanks for the update about Java 8, I have been struggling to get these versions to uninstall. My other scripts work perfectly with 6/7…

    One thing I noticed while testing through SCCM, is that I had 2 test machines, with 32 and 64 bit versions installed on both. One removed 32bit, and on the other machine it removed 64bit. The deployment completed with success. I’m not sure if it would do the same if I had lets say a java 6 and 7 32bit version installed and only removed one, but i have 2600 machines that up until now, have about 50 different versions across our environment, and many users have multiple versions installed. What do we need to modify in the code to loop until it does not detect any more versions installed before ending?

    Thanks guys.

    • I guess there’s two options. With SCCM you could set up the advertisement to rerun on a schedule. Thats a bit quick and dirty but would work well if you are concerned java may get reinstalled later. Orherwise I’ll have a look at some more of these complex scenarios and test them fully to see what I need to change.

  6. Dan says:

    First off, thanks a lot for the script. I’m very new to powershell, can anyone point me in the right direction as to how to run this script using Altiris? (similar to SCCM)

    Do I need to copy the .ps1 file to the local PC where I’m deploying to first? What is the syntax to run powershell scripts?

  7. Craig says:

    When I run this script with the WhatIf switch it lists the 2 versions of java I have installed, but when I run it normally nothing uninstalls.
    Any ideas?

  8. Craig says:

    The following is what I get running with -Verbose however the java 8 still remains.

    C:\Users\xxxxxx>powershell -File c:\script\uninstall-java.ps1 -Keepversion 7.0.7
    1 -Verbose
    VERBOSE: Exporting function ‘Get-FileHash’.
    VERBOSE: Exporting function ‘Get-SerializedCommand’.
    VERBOSE: Script Started 02/26/2015 07:08:48
    VERBOSE: Java is Installed
    VERBOSE: Uninstalling Java 8 Update 31
    VERBOSE: Script Complete 02/26/2015 07:08:51

  9. Todd says:

    Craig,

    I really like the script, however, when I use it in a group policy (startup PS script), if any of the installers “fail” rather than sending the failure dialog boxes to a log file, or into the oblivion of null, it’s popping them up “behind” the “Please Wait” Windows 7 boot-up screen (the screen prior to the “CTRL-ALT-DEL” screen. The only way to “fix” this that I’ve found is to remotely (using taskkill) kill the powershell.exe process which then allows the user to log in. The error that I’ve seen (I’m sorry, I don’t have the screenshot) is something to the affect of not being able to locate installer.dll or something like that.

    I guess I was just wondering if there are any commands or switches that can be placed into the script to tell the uninstaller to do so completely silently and to never ever pop up a dialog box.

    Thanks again for the work on this.

    Todd Oo.

    • Thanks Todd,

      Could you post the full syntax of the command you’re using in the startup script GPO and what versions of Java it may be uninstalling? I had a look at the code and I’m not totally sure how that error message can be presenting on screen but I’ll see if I can replicate the problem and remove any on screen messages..

    • My other thought having pondered on your comment is that it might not be the best way to run the script. Loading up the start up process with scripts, like this one, will slow down the logon process as well as create potential problems at logon (Like you are hitting). What about using the PS startup script to create scheduled tasks that can then execute asynchronously from the logon process (maybe by triggering on user logon or system start up)?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s