{"id":11432,"date":"2024-11-04T10:29:47","date_gmt":"2024-11-04T15:29:47","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=11432"},"modified":"2025-02-10T12:29:00","modified_gmt":"2025-02-10T17:29:00","slug":"powershell-to-uninstall-an-application","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=11432","title":{"rendered":"PowerShell to Uninstall an Application"},"content":{"rendered":"\n<p>I was curious if, instead of getting prompted for the local admin account for each application I want to remove, I could run PowerShell &#8220;as a different user&#8221; then use it to uninstall an application or list of applications. In this case, all of the .NET 6 stuff. Answer: absolutely. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\n# List all installed applications containing string &quot;NET&quot;\n# Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -like &#039;*NET*&#039; } | Select-Object -Property Name\n\n# Define a static list of application names to uninstall\n$appsToUninstall = @(\n    &#039;Microsoft .NET Runtime - 6.0.36 (x86)&#039;,\n    &#039;Microsoft .NET Host FX Resolver - 6.0.36 (x64)&#039;,\n    &#039;Microsoft .NET Host - 6.0.36 (x64)&#039;,\n    &#039;Microsoft .NET Host FX Resolver - 6.0.36 (x86)&#039;,\n    &#039;Microsoft .NET Host - 6.0.36 (x86)&#039;,\n    &#039;Microsoft .NET Runtime - 6.0.36 (x64)&#039;,\n    &#039;Microsoft.NET.Workload.Emscripten.net6.Manifest (x64)&#039;\n)\n\n# Loop through each application name in the static list\nforeach ($appName in $appsToUninstall) {\n    # Find the application object by name\n    $app = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -eq $appName }\n    \n    # Check if the application was found before attempting to uninstall\n    if ($app) {\n        Write-Output &quot;Uninstalling $($app.Name)...&quot;\n        $app.Uninstall() | Out-Null\n        Write-Output &quot;$($app.Name) has been uninstalled successfully.&quot;\n    }\n    else {\n        Write-Output &quot;Application $appName not found.&quot;\n    }\n}\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>I was curious if, instead of getting prompted for the local admin account for each application I want to remove, I could run PowerShell &#8220;as a different user&#8221; then use it to uninstall an application or list of applications. In this case, all of the .NET 6 stuff. Answer: absolutely.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[622,136],"class_list":["post-11432","post","type-post","status-publish","format-standard","hentry","category-system-administration","tag-powershell","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/11432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11432"}],"version-history":[{"count":2,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/11432\/revisions"}],"predecessor-version":[{"id":11434,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/11432\/revisions\/11434"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}