• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

TECHDIIP

  • Tech
  • Windows
  • Powershell
  • Scripts
  • News
  • Games

Powershell script to uninstall applications

If you are looking for a script to uninstall applications remote on windows 10 desktop computer or windows server 2016 computer then you are at the right place, here in this article we explain how a Powershell Script can uninstall applications on multiple remote computers.

We can uninstall any software using Powershell script, there are two methods available, using the WMI method and uninstall registry string. Generally, windows administrator deal with many servers and desktop machines every day as part of their work and they work on product uninstallation and upgrades, using Powershell script user interaction is not required, one can automate the uninstallation process and same with uninstalling registry string, here are the simple steps this article explains how this script can uninstall any software without any user interaction.

We need to create a text file for remote computers list that we are going to uninstall applications, here I have created a text file named as allservers.txt and saved it in location C\temp\allservers.txt

function UninstallApplication{
   param
   (
   [Parameter(Position=0, Mandatory = $true, HelpMessage="Enter CompuerName", ValueFromPipeline = $true)] 
   $ServerName,
   [Parameter(Position=1, Mandatory = $true, HelpMessage="Enter ApplicationName", ValueFromPipeline = $true)]
   $Application
   )
  
   $Object = New-Object PSCustomObject
   $Object | Add-Member -MemberType NoteProperty -Name "ServerName" -Value $ServerName
   $Object | Add-Member -MemberType NoteProperty -Name "Application" -Value $Application
   return $Object
}
 
$Allservers = get-content -Path "C:\temp\Allservers.txt"
 
foreach($oneserver in $Allservers)
{
 
    $ApplicationName = $oneserver.applicationName
    $MachineName = $oneserver.servername
 
    $application = Get-WmiObject -Class Win32_Product -MachineName $MachineName -Filter "Name='$ApplicationName'"
    If($application -ne $null)
    {
        $output = $application.Uninstall()
        If ($output.ReturnValue -eq 0)
        {   
            Write-Verbose -Verbose "[$(Get-Date)] - $MachineName  $($application.name) Uninstalled!"
            
        }
        Else
        {   
            Write-Error -Verbose "[$(Get-Date)] - $MachineName  $($application.name) Uninstallation is failed!  Error code: $($output.ReturnValue)"
           
        }
    }
    Else
    {
        Write-Verbose -Verbose "[$(Get-Date)] - $MachineName Can not find the $ApplicationName"
       
    }
}

Usage of the script:

we need to run this function on a Powershell on a server or desktop machine where you have administrator privileges, and also on the remote computers where you are uninstalling the software.

C:\UninstallApplication -ServerName win2016 -Application MSOFFICE

Thank you for reading this article, if you have any questions please let us know.

Thank you for visiting my site, for any scripts in these articles you are testing please make sure you have tested this script in our lower environment before you run in production.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • How do Zoom Application Testing | Working or Not
  • Powershell script to test website status up or down on a local or remote computers
  • Solved: Server execution failed windows 10 Server 2016 and 2019
  • How to Fix windows 10 version 1903 error 0xc1900223
  • Free Music Making Software List One Can Try Out
  • About Us
  • CONTACT US
  • Disclaimer
  • Privacy Policy

Copyright © 2023 techdiip.com