Need to uninstall Java with SCCM deployment

TechUST 561 Reputation points
2025-02-11T04:06:55.6233333+00:00

In my environment, I need to uninstall Java from machines. Multiple versions of Java are installed, but I want to deploy a single script that can uninstall Java regardless of its version. Could you please suggest a PowerShell script to achieve this objective?

Microsoft System Center
Microsoft System Center
A suite of Microsoft systems management products that offer solutions for managing datacenter resources, private clouds, and client devices.
1,074 questions
Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
5,552 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,809 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AllenLiu-MSFT 47,811 Reputation points Microsoft Vendor
    2025-02-11T05:36:05.1833333+00:00

    Hi, @TechUST

    Thank you for posting in Microsoft Q&A forum.

    To uninstall Java from machines using a PowerShell script, you can utilize the Get-WmiObject cmdlet to find all versions of Java installed on the system and then uninstall them. Below is a sample PowerShell script that achieves this:

    # Get all installed Java products
    $javaProducts = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -like "Java*" }
    
    # Uninstall each Java product found
    foreach ($product in $javaProducts) {
        $product.Uninstall()
    }
    

    This script retrieves all installed products whose names start with "Java" and uninstalls each one. You can deploy this script using SCCM to remove Java from the target machines.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Add comment".

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.