• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

TECHDIIP

  • Tech
  • Windows
  • Powershell
  • Scripts
  • News
  • Games

Uninstall Java Using Powershell Script

Java can be uninstalled using a simple Powershell script on a workstation or a Windows server operating system. This simple Powershell script runs remotely on the remote computers and uninstalls java in a silent mode, without any user interaction.

Do you know there are two methods we can use for uninstalling the JAVA, the first method is using the registry key, and the second method is using the WMI method. If you are working for a large enterprise company as a system admin or an analyst has to maintain the software’s as per industry standards and compliance, we have to upgrade newer version whenever it is out, in this article we explain how java can be uninstalled, later one can upgrade to a newer version.

Uninstall Java on local machine using WMI method

gwmi Win32_Product -filter "name like 'Java%' AND vendor like 'Oracle%' AND
not version = '8.0.2510.8'" | % { $_.Uninstall() }

The above one-line powershell code uninstalls the Java on your local computer, I have java version 8.0.2510.8 installed on my windows computer, it might different version you have it, change it version name as yours.

Uninstall Java on multiple remote computers

Java can be uninstalled using the registry method, we need to locate the uninstall registry key, In my case, I have installed Java 64 bit application located and the path is HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall

Here is the screenshot of the JAVA software uninstall string.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{26A24AE4-039D-4CA4-87B4-2F64180251F0}

Uninstall Java Using Powershell Script
MsiExec.exe /X {26A24AE4-039D-4CA4-87B4-2F64180251F0}

We need to make a batch file to copy it to all remote computer where needs to be removed, this batch we will use it in our powershell to run and perform the uninstall.

@each off

:Java Uninstall Using powershell

MsiExec.exe /X {26A24AE4-039D-4CA4-87B4-2F64180251F0} /qn

exit

Just copy the above code in a notepad file and save it as java-uninstall.bat, remember each java version has different uninstall registry string, make sure you have put the right java uninstall string, here is the screenshot.

  • Uninstall Java Using Powershell Script

We need to create a file for storing all the servers or multiple machines list, I named it as Allservers.txt and saved it in my local machine c:\temp\Allservers.txt

#remote machines list 
$machines= Get-Content -Path "C:\temp\AllServers.txt" 
foreach ($onemachine in $machines) 
{ 
#java uninstall location file and where to copy on the remote system

Copy-Item -Path "\\sourcemachine\c$\java\java-uninstall.bat" -Destination "\\$onemachine\c$\temp" -Recurse -force

Invoke-command -ComputerName $onemachine -Scriptblock {C:\temp\java-uninstall.bat} -Asjob

}

The above simple code copies the uninstall java bat file on the remote computers and uninstalls the java program, each computer execution runs a background job and finishes the un-installation, wait for all jobs to complete, to get the running job status, use the command get-job -state running.

I hope you find this article useful, if you have any questions please let us know.

Thank you for visiting my site, for any scripts in these articles you are testing please make sure you have tested this script in our lower environment before you run in production.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • How do Zoom Application Testing | Working or Not
  • Powershell script to test website status up or down on a local or remote computers
  • Solved: Server execution failed windows 10 Server 2016 and 2019
  • How to Fix windows 10 version 1903 error 0xc1900223
  • Free Music Making Software List One Can Try Out
  • About Us
  • CONTACT US
  • Disclaimer
  • Privacy Policy

Copyright © 2023 techdiip.com