Need script for java uninstallation

TechUST 581 Reputation points
2025-03-07T04:39:59.7066667+00:00

I am looking for a script that can uninstall Java JDK and JRE from the system but should not uninstall OpenJDK

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,859 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ian Xue-MSFT 40,591 Reputation points Microsoft External Staff
    2025-03-07T07:59:58.5766667+00:00

    Hi TechUST,

    Please try the following command to uninstall JDK.

    Get-CimInstance -ClassName Win32_Product -Filter "name like 'Java%' AND vendor like 'Oracle%'" | Invoke-CimMethod -MethodName Uninstall 
    

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.

    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.