{"id":3430,"date":"2024-06-21T12:51:47","date_gmt":"2024-06-21T17:51:47","guid":{"rendered":"https:\/\/microsoftgeek.com\/?p=3430"},"modified":"2024-06-21T13:02:57","modified_gmt":"2024-06-21T18:02:57","slug":"powershell-uninstall-java-from-windows-computers","status":"publish","type":"post","link":"https:\/\/microsoftgeek.com\/?p=3430","title":{"rendered":"PowerShell: Uninstall Java from Windows computers"},"content":{"rendered":"\n<p>Here&#8217;s a PowerShell script to uninstall Java from Windows computers. This script uses the Get-WmiObject cmdlet to find the Java application and the Invoke-Expression cmdlet to uninstall it.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>cmdlet to uninstall it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>powershellCopy code<code># PowerShell script to uninstall Java from Windows computers\n\n# Function to uninstall a program by name\nfunction Uninstall-Program {\n    param (\n        &#91;string]$programName\n    )\n\n    # Get the list of installed programs\n    $installedPrograms = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -like \"*$programName*\" }\n\n    foreach ($program in $installedPrograms) {\n        Write-Host \"Uninstalling $($program.Name)...\"\n        $program.Uninstall() | Out-Null\n        Write-Host \"$($program.Name) has been uninstalled.\"\n    }\n}\n\n# Uninstall Java\n$javaProgramName = \"Java\"\nUninstall-Program -programName $javaProgramName\n\nWrite-Host \"Java uninstallation process completed.\"\n<\/code><\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>This script performs the following steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Defines a function Uninstall-Program that takes the program name as a parameter.<\/li>\n\n\n\n<li>Uses Get-WmiObject to retrieve a list of installed programs that match the provided name.<\/li>\n\n\n\n<li>Iterates through the list of matching programs and uninstalls each one.<\/li>\n\n\n\n<li>Uninstalls Java by calling the Uninstall-Program function with &#8220;Java&#8221; as the program name.<\/li>\n<\/ol>\n\n\n\n<p>You can run this script in a PowerShell window with administrative privileges.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a PowerShell script to uninstall Java from Windows computers. This script uses the Get-WmiObject cmdlet to find the Java application and the Invoke-Expression cmdlet to uninstall it. cmdlet to uninstall it. This script performs the following steps: You can run this script in a PowerShell window with administrative privileges.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-3430","post","type-post","status-publish","format-standard","hentry","category-computer-tech-stuff"],"_links":{"self":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/3430","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3430"}],"version-history":[{"count":5,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/3430\/revisions"}],"predecessor-version":[{"id":3443,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/3430\/revisions\/3443"}],"wp:attachment":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}