{"id":4876,"date":"2023-09-18T10:33:36","date_gmt":"2023-09-18T17:33:36","guid":{"rendered":"https:\/\/SUMMALAI.COM\/?p=4876"},"modified":"2023-09-18T10:33:38","modified_gmt":"2023-09-18T17:33:38","slug":"how-to-uninstall-software-using-powershell","status":"publish","type":"post","link":"https:\/\/SUMMALAI.COM\/?p=4876","title":{"rendered":"How to Uninstall Software Using PowerShell"},"content":{"rendered":"\n<p>Most of us have uninstalled programs from our PCs. How have you done it? Can you recollect?<\/p>\n\n\n\n<p>We\u2019ve done it mostly using the Control Panel or in some cases, if dealing with more complex suites, their own uninstall process.&nbsp;<\/p>\n\n\n\n<p>These options are convenient to remove a single program, they\u2019re not scalable. Imagine for a moment you\u2019re an IT admin and want to remove programs from multiple computers. Logging into each device and uninstalling a program isn\u2019t the most productive option.<\/p>\n\n\n\n<p>Thankfully, you can use&nbsp;<a href=\"https:\/\/techgenix.com\/powershell-scripts\/\">PowerShell scripts<\/a>&nbsp;to uninstall software. The advantage is you can&nbsp;<strong>send any number of networked PCs an uninstall command<\/strong>.&nbsp;This way, you can&nbsp;<strong>uninstall a program from thousands of PCs with just one script<\/strong>.<\/p>\n\n\n\n<p>Sounds simple, right? Let\u2019s jump in and see how to uninstall software using PowerShell.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is Microsoft PowerShell?<\/strong><\/h2>\n\n\n\n<p><a href=\"https:\/\/techgenix.com\/powershell-essentials-part1\/\">Microsoft PowerShell<\/a>&nbsp;is a&nbsp;<strong>task automation and configuration manager<\/strong>&nbsp;consisting of a scripting language and a command-line prompt. It comes with many built-in commands called cmdlets that perform a specific function or task. You can combine these cmdlets into a custom script to&nbsp;<strong>perform the desired task<\/strong>&nbsp;\u2013 automating complex or time-consuming tasks.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2 Ways to Uninstall Software Using PowerShell<\/strong><\/h2>\n\n\n\n<p>You can uninstall software using PowerShell&nbsp;<strong>in 2 ways<\/strong>, the&nbsp;<strong><em>Uninstall()<\/em><\/strong>&nbsp;method and the&nbsp;<strong><em>Uninstall-Package<\/em><\/strong>&nbsp;command. Out of the two, the&nbsp;<strong><em>Uninstall()<\/em><\/strong>&nbsp;method is the most popular and the easiest option to remove well-known programs from a device.&nbsp;<\/p>\n\n\n\n<p>The second option is the&nbsp;<strong><em>Uninstall-Package<\/em><\/strong>,&nbsp;it\u2019s a good choice for hidden programs and ones PowerShell doesn\u2019t identify.&nbsp;<\/p>\n\n\n\n<p>Let\u2019s start with the first option.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Uninstall Method<\/strong><\/h3>\n\n\n\n<p>In this step-by-step guide, you\u2019ll learn the commands to uninstall a software from a single computer. You can always use a For-each loop to&nbsp;<strong>extend it to a collection or array of PCs<\/strong>&nbsp;to iterate through every computer in the array and perform the same action.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 1:&nbsp; Get the List of Installed Applications&nbsp;<\/strong><\/h4>\n\n\n\n<p>As a first step, get the list of applications installed on a computer. The PowerShell code for that is:<\/p>\n\n\n\n<p><strong><em>Get-WmiObject -Class Win32_Product | Select-Object -Property Name<\/em><\/strong><\/p>\n\n\n\n<p>Now, you may wonder what\u2019s the need to get the list of installed&nbsp;<a href=\"https:\/\/techgenix.com\/application-layering-with-virtual-hard-disks-and-powershell\/\">applications<\/a>? After all, you only need to remove one application from the computer. The catch is you must know the application\u2019s exact name as PowerShell reads and displays it. For example, you may use the words \u201cMicrosoft Outlook\u201d in your code to uninstall Outlook from a computer. What if it\u2019s called \u201cMicrosoft Outlook 2019\u201d? This mismatch will either throw an error message or the command will simply not execute. Avoid any confusion and see how PowerShell reads a software\u2019s name and then, use this name exactly in your code to uninstall.&nbsp;<\/p>\n\n\n\n<p>Here is an example, the image below shows how&nbsp;<strong><em>Get-WmiObject&nbsp;<\/em><\/strong>displays the installed programs\u2019 list.<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_1052953\"><img decoding=\"async\" src=\"https:\/\/techgenix.com\/tgwordpress\/wp-content\/uploads\/2022\/02\/2-2.png\" alt=\"PowerShell command line interface showing PowerShell\u2019s Get-WmiObject command returning a complete list of installed programs. \" class=\"wp-image-1052953\"\/><figcaption>PowerShell\u2019s Get-WmiObject command returning a complete list of installed programs.<\/figcaption><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 2: Narrow the List<\/strong><\/h4>\n\n\n\n<p>The programs\u2019 list above can look overwhelming, even on devices with just a few installed programs. You can narrow it down using filters and regular expressions if you have an idea of your program\u2019s name. In the above example, you can ask PowerShell to narrow the list to programs that contain the word \u201cOutlook\u201d as this is a unique word. If you use \u201cMicrosoft\u201d, you can end up with a bigger list! In general, make sure you pick the expressions and words that have the best chance to help you find the program you want.&nbsp;<\/p>\n\n\n\n<p><strong><em>$MyProgram = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq \u201cOutlook\u201d}<\/em><\/strong><\/p>\n\n\n\n<p>This will narrow down the list to all the Microsoft Outlook versions installed in your system. From this list, pick the version you want to uninstall. If you have only one version installed, then nothing to pick, and&nbsp;<strong><em>MyProgram&nbsp;<\/em><\/strong>stores the value in the variable.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 3: Use the Uninstall Method<\/strong><\/h4>\n\n\n\n<p><a href=\"https:\/\/techgenix.com\/powershell-comparison-operators\/\">PowerShell&nbsp;<\/a>comes with a built-in method called&nbsp;<strong><em>Uninstall()<\/em><\/strong>. Simply call this method on your program to uninstall it. In our above example, it\u2019ll be<\/p>\n\n\n\n<p><strong><em>$MyProgram.uninstall()<\/em><\/strong><\/p>\n\n\n\n<p>This command will uninstall your program. You can also replace the variable&nbsp;<strong><em>$MyProgram<\/em><\/strong>&nbsp;with the actual program name.&nbsp;<\/p>\n\n\n\n<p>This process is the easiest way to uninstall a program using PowerShell. That said, some hidden programs may exist and they won\u2019t get listed with the&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/microsoft.powershell.management\/get-wmiobject?view=powershell-5.1\">Get-WmiObject<\/a>&nbsp;command.<\/p>\n\n\n\n<p>Open your Control Panel and see programs\u2019 list on it to test this. Compare it with the list PowerShell displays and you\u2019ll notice some aren\u2019t included.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Use Uninstall-Package<\/strong><\/h3>\n\n\n\n<p>Use this option if PowerShell doesn\u2019t list your program. The code for this PowerShell command is,<\/p>\n\n\n\n<p><strong><em>Get-Package -Provider Programs -IncludeWindowsInstaller -Name \u201cBackZilla\u201d<\/em><\/strong><\/p>\n\n\n\n<p>To get PowerShell to display all the programs on the<strong><em>&nbsp;Control Panel<\/em><\/strong>, use an asterisk in place of the Name parameter. Note that if you\u2019ve installed multiple versions, this command uninstalls only the latest version.&nbsp;<\/p>\n\n\n\n<p>In the above example, it will be:<\/p>\n\n\n\n<p><strong><em>Uninstall-Package -Name BackupZilla 3.0<\/em><\/strong><\/p>\n\n\n\n<p>You can also choose to uninstall a specific version or pipe the output of Get-Package to&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/packagemanagement\/uninstall-package?view=powershell-7.2\">Uninstall-Package<\/a>. Here\u2019s an example.<\/p>\n\n\n\n<p><strong><em>Get-Package -Name BackupZilla -RequiredVersion 2.0 | Uninstall-Package<\/em><\/strong><\/p>\n\n\n\n<p>Thus, this is how you can uninstall any program from a device, even if they\u2019re hidden!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Comparison of Both Uninstall Methods<\/strong><\/h2>\n\n\n\n<p>So, which of two should you choose? If&nbsp;<strong><em>Get-WmiObject&nbsp;<\/em><\/strong>displays a program you have, the Uninstall method is the easier choice. That said, if you have to create a custom script to remove programs across multiple computers, go for the Uninstall-Package.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Final Words<\/strong><\/h2>\n\n\n\n<p><a href=\"https:\/\/techgenix.com\/use-powershell-get-modern-app-background-task-performance-usage\/\">PowerShell scripts<\/a>&nbsp;are convenient to remove a program across multiple devices. You can automate this process and save time and effort with just a few lines of code. You can uninstall software using PowerShell in 2 ways \u2013 the&nbsp;<strong><em>Get-WmiObject<\/em><\/strong>&nbsp;and&nbsp;<strong><em>Uninstall-Package<\/em><\/strong>. Out of the two, the&nbsp;<strong><em>Uninstall-package<\/em><\/strong>&nbsp;has more options and comes with wider access to normal and hidden programs while the&nbsp;<strong><em>Get-WmiObject<\/em><\/strong>&nbsp;command can only use the associated WMI classes.&nbsp;<\/p>\n\n\n\n<p>Which of the two is better? It depends on the software you want to uninstall. If PowerShell\u2019s\u00a0<strong><em>Get-WmiObject\u00a0<\/em><\/strong>recognizes it, go with this option as it\u2019s easier. Otherwise, use\u00a0<strong><em>Uninstall-Package<\/em><\/strong>.\u00a0<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Ref: https:\/\/techgenix.com\/how-to-uninstall-software-using-powershell\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most of us have uninstalled programs from our PCs. How have you done it? Can you recollect? We\u2019ve done it mostly using the Control Panel or in some cases, if dealing with more complex suites, their own uninstall process.&nbsp; These options are convenient to remove a single program, they\u2019re not scalable. Imagine for a moment <a class=\"read-more\" href=\"https:\/\/SUMMALAI.COM\/?p=4876\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1185,1249,10],"tags":[1681,1680],"class_list":["post-4876","post","type-post","status-publish","format-standard","hentry","category-autopilot-intune","category-azure-microsoft","category-microsoft","tag-uninstall-apps-powershell","tag-uninstall-software-using-powershell"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/4876","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4876"}],"version-history":[{"count":1,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/4876\/revisions"}],"predecessor-version":[{"id":4878,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/4876\/revisions\/4878"}],"wp:attachment":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4876"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4876"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4876"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}