07 August 2013

Application Uninstall Script

This script will uninstall an application with just the partial description that is listed in Add/Remove programs. It searches the product list and then grabs the GUID to use in the MSI uninstallation. At current, it will only uninstall apps that use an MSI installer. I am going to be updating this script to be able to use executables also.

You can download the script from here.

 Function UninstallOldApplication($Description) {  
      #Declare Local Memory  
      Set-Variable -Name AppName -Scope Local -Force  
      Set-Variable -Name Arguments -Scope Local -Force  
      Set-Variable -Name Code -Scope Local -Force  
      Set-Variable -Name GUID -Scope Local -Force  
      Set-Variable -Name Output -Scope Local -Force  
      #Change '%application%' to whatever app you are calling  
      $Description = [char]34+"description like"+[char]32+[char]39+[char]37+$Description+[char]37+[char]39+[char]34  
      $Output = wmic product where $Description get IdentifyingNumber  
      $Output1 = wmic product where $Description get Description  
      $Output1 | ForEach-Object {  
           $_ = $_.Trim()  
        if(($_ -ne "Description")-and($_ -ne "")){  
          $AppName = $_  
        }  
      }  
      Write-Host "Uninstalling"$AppName"....." -NoNewline  
      $Output | ForEach-Object {  
           $_ = $_.Trim()  
        if(($_ -ne "IdentifyingNumber")-and($_ -ne "")){  
          $GUID = $_  
        }  
      }  
      $Arguments = "/X"+[char]32+$GUID+[char]32+"/qb- /norestart"  
      $Code = (Start-Process -FilePath "msiexec.exe" -ArgumentList $Arguments -Wait -Passthru).ExitCode  
      If ($Code -eq 0) {  
           Write-Host "Uninstalled" -ForegroundColor Yellow  
      } else {  
           Write-Host "Failed" -ForegroundColor Red  
      }  
      #Cleanup Local Memory  
      Remove-Variable -Name AppName -Scope Local -Force  
      Remove-Variable -Name Arguments -Scope Local -Force  
      Remove-Variable -Name Code -Scope Local -Force  
      Remove-Variable -Name GUID -Scope Local -Force  
      Remove-Variable -Name Output -Scope Local -Force  
      Remove-Variable -Name Output1 -Scope Local -Force  
 }  

Related Posts:

  • Dell Client System Update for the SCCM & MDT Build The DCSU is a great utility that Dell has made available to update the drivers and driver applications on Dell systems. The industry I work in requires specific drivers for specific applications, which makes the DCSU not a… Read More
  • Application Uninstall Script This script will uninstall an application with just the partial description that is listed in Add/Remove programs. It searches the product list and then grabs the GUID to use in the MSI uninstallation. At current, it will o… Read More
  • Find out who is logged on and logged off Being an SCCM administrator, I often have to log into machines to see if a deployment went ok. Trying to login to machines and getting the message that someone is already logged in gets tiring. Ed Wilson originally wrote a … Read More
  • Add/Remove Program entries Sometimes it is necessary to add an add/remove programs entry. There are instances where an application is independent and requires not installation and you want to make sure it is copied to the system, or you use add/remov… Read More
  • Robocopy User Profile Contents to UNC Path The Windows 10 upgrades required us to move profile contents off of the machines to a file share and then move them back. This was because USMT could not be used due to the architecture changing from 32-bit to 64-bit. This … Read More

1 comments:

  1. Hi Mick, i'm getting 1603 error code. how can i force the script to press yes in dialouge box?

    ReplyDelete