Removing Old Java Versions with PowerShell

choubertsprojects

The Best WordPress plugins!

1. WP Reset

2. WP 301 Redirects

3. WP Force SSL

Java is an old programming language that has been used since 1995. It continues to be widely used by developers, but it’s also a security risk because of its age and how easily outdated it can become. For example, Oracle Java 6 was recently deemed unsafe and Oracle announced they will no longer support or update the software after January 2019 as part of their sunset strategy for the product. This leaves organizations with two options: either stop using Java completely, or remove all instances from within Windows’ operating system so users cannot install any new versions in future

The “remove old java versions” is a PowerShell command that removes all Java versions older than the specified version. The command is useful for removing old Java versions when upgrading to a newer version of Java.

Removing Old Java Versions with PowerShell

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

Out-Null New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT | New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT Get-ChildItem $ClassesRootPath | Where-Object (

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘ProductName’) -like ‘*Java*’) | Foreach

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.PsPath -Force -Recurse $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) $JavaSoftPath -Force -Recurse Remove-Item

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

Out-Null New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT | New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT Get-ChildItem $ClassesRootPath | Where-Object (

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘ProductName’) -like ‘*Java*’) | Foreach

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.PsPath -Force -Recurse $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) $JavaSoftPath -Force -Recurse Remove-Item

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

Out-Null New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT | New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT Get-ChildItem $ClassesRootPath | Where-Object (

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘ProductName’) -like ‘*Java*’) | Foreach

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.PsPath -Force -Recurse $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) $JavaSoftPath -Force -Recurse Remove-Item

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

Out-Null New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT | New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT Get-ChildItem $ClassesRootPath | Where-Object (

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘ProductName’) -like ‘*Java*’) | Foreach

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.PsPath -Force -Recurse $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) $JavaSoftPath -Force -Recurse Remove-Item

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

Out-Null New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT | New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT Get-ChildItem $ClassesRootPath | Where-Object (

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘ProductName’) -like ‘*Java*’) | Foreach

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.PsPath -Force -Recurse $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) $JavaSoftPath -Force -Recurse Remove-Item

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

Out-Null New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT | New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT Get-ChildItem $ClassesRootPath | Where-Object (

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘ProductName’) -like ‘*Java*’) | Foreach

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.PsPath -Force -Recurse $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) $JavaSoftPath -Force -Recurse Remove-Item

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

Out-Null New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT | New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT Get-ChildItem $ClassesRootPath | Where-Object (

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘ProductName’) -like ‘*Java*’) | Foreach

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.PsPath -Force -Recurse $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) $JavaSoftPath -Force -Recurse Remove-Item

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

Out-Null New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT | New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT Get-ChildItem $ClassesRootPath | Where-Object (

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘ProductName’) -like ‘*Java*’) | Foreach

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.PsPath -Force -Recurse $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) $JavaSoftPath -Force -Recurse Remove-Item

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

Out-Null New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT | New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT Get-ChildItem $ClassesRootPath | Where-Object (

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘ProductName’) -like ‘*Java*’) | Foreach

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.PsPath -Force -Recurse $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) $JavaSoftPath -Force -Recurse Remove-Item

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

Out-Null New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT | New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY CLASSES ROOT Get-ChildItem $ClassesRootPath | Where-Object (

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘ProductName’) -like ‘*Java*’) | Foreach

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = ((

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’) -eq ‘Oracle Corporation’) -and ($VersionsToKeep -notcontains

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Select-Object @n=’Name’;e=$ .Name.Split(‘.’)[0] | Get-CimInstance -ClassName ‘Win32 Process’ | Where-Object

Java runtime environments may spread like wildfire in an organization if left unmanaged. When I ran a report to see how the Java landscape in my environment looked, I discovered 62 distinct versions of Java! It’s time to reclaim control and create a PowerShell script to uninstall outdated Java versions.

In this article, you’ll learn how to use PowerShell to construct a Java removal tool for deleting outdated Java.

Let’s get this party started!

The Scripting Process

First, open the file in your preferred code editor, such as Visual Studio Code, and save it as Remove-Java.ps1. This PowerShell script includes everything you’ll need to get rid of old Java versions.

Make a list of the registry paths.

Because Java instances might hide in two different locations in the registry, specify each of the parent registry keys first. Both the 32-bit and 64-bit registry paths are provided in the code sample below.

@(‘HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’) $RegUninstallPaths = @(‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall’, ‘HKLM:SOFTWAREWow6432NodeMicrosoftWindowsC

Make a list of the versions you want to save.

Create an array containing each of the versions you’d want to preserve, since you’ll undoubtedly want to keep some old Java versions around.

In the Control Panel, search under Programs and Features to discover the precise wording to use.

@(‘Java 8 Update 261’) $VersionsToKeep =

Locate and terminate all currently running processes.

Next, locate all Java processes that are currently active. The code snippet below enumerates any running WMI processes that have a file in a directory that matches “Program FilesJava.”

Because Java may implant itself in Internet Explorer and cannot be uninstalled, halt all Internet Explorer processes as well.

Get-CimInstance -ClassName ‘Win32_Process’ | Where-Object {$_.ExecutablePath -like ‘*Program FilesJava*’} | Select-Object @{n=’Name’;e={$_.Name.Split(‘.’)[0]}} | Stop-Process -Force Get-process -Name *iexplore* | Stop-Process -Force -ErrorAction SilentlyContinue

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.ExecutablePath -like ‘*Program FilesJava*’ | Stop-Process -Force Stop-Process -Force -ErrorAction SilentlyContinue Get-process -Name *iexplore*

Force an uninstall of Java by searching for it in the registry.

Create a filter to enumerate all of the values under the registry keys you established before. This filter locates all Java instances and filters out any versions you want to preserve.

$UninstallSearchFilter = {($_.GetValue(‘DisplayName’) -like ‘*Java*’) -and (($_.GetValue(‘Publisher’) -eq ‘Oracle Corporation’)) -and ($VersionsToKeep -notcontains $_.GetValue(‘DisplayName’))}

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.GetValue(‘DisplayName’))

Now examine the registry for any Java instances and, if any are discovered, use msiexec.exe /X to destroy them.

# Clean up program files and uninstall unnecessary Java versions foreach ($Path in $RegUninstallPaths) if (Test-Path $Path) Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach Start-Process ‘C:WindowsSystem32msiexec.exe’ “/X$($ .PSChildName) /qn” -Wait

Remove any leftover Java code.

Remove any leftovers that the Java uninstaller did not remove on its own.

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | Out-Null $ClassesRootPath = “HKCR:InstallerProducts” Get-ChildItem $ClassesRootPath | Where-Object { ($_.GetValue(‘ProductName’) -like ‘*Java*’)} | Foreach { Remove-Item $_.PsPath -Force -Recurse } $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) { Remove-Item $JavaSoftPath -Force -Recurse }

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

.PsPath -Force -Recurse $JavaSoftPath = ‘HKLM:SOFTWAREJavaSoft’ if (Test-Path $JavaSoftPath) $JavaSoftPath -Force -Recurse Remove-Item

Wrap up

That’s all there is to it! To make this procedure as easy as possible, run this PowerShell script on each machine where you want to wipe up Java.

Please feel free to download the complete script in one go from the links below.

Thanks to Sam Turner for assisting me with the correction of certain errors in this code.

The “java uninstall tool msi” is a PowerShell script that can be used to remove old Java versions. It also removes any other version of Java that may have been installed. This can be done by running the command “Get-InstalledJava”.

Frequently Asked Questions

How do I remove old versions of Java?

A: Depending on your operating system, you should be able to remove old versions of Java and other software through the following steps.
For Mac OS X 10.6-10.8 Users:
1) Click the Apple logo in the top left corner of the screen 2) Type java into Spotlight 3) Select Open 4) Choose Quit 5) From now on, never launch Java or any other application that is installed by clicking its icon 6). Make sure all applications are closed before starting a new process 7), For Windows 8/8.1/10 users follow these steps 1): Press Win+x keys together from your keyboard simultaneously 2): Type “Control Panel” in search bar at bottom right 3): In Control Panel click Programs and Features tab 4): Find out programs and features including J2SE Runtime Environment (JRE), Oracle JDK, Java Development Kit(JDK), then uninstall them 5 – The same as with Windows 7; it will take multiple clicks to find everything

How do I remove old Java from Windows 10?

A: Java is a program that allows you to run programs and games without the need for installation. To remove it, follow these steps:
1. Click on Start Menu2. Type Control Panel in search3. Select Control Panel4(If not already open)5.. Double-click Programs6.(In Programs & Features section)7… Find Java8(Right click to uninstall or use Add/Remove Windows Components9.)

Do I need to remove old Java versions?

A: You will have to remove all previous versions of Java from your computer, including the ones that come with Windows or Mac.

Related Tags

  • install java powershell
  • powershell change java version
  • powershell download and install java
  • java uninstall command line
  • uninstall all versions of java batch file

Table of Content