Search code examples
powershellwindows-installerexewmi

is there an universal line to delete/uninstall any application?


is there an universal line to delete/uninstall any application that is shown in control panel? preferably PowerShell but can be another language. I have lines that delete .msi not .EXE. this part has been quite difficult, I am not knowledgeable in differences between .EXE and .MSI, if anyone has any idea how I could differentiate them so I could at least get .msi solved

here is the code I se for .msi

$ComputerName = Read-Host -Prompt 'Input the computer name' # the name of the computer to remove the app from

Get-WmiObject Win32_Product -ComputerName $ComputerName | Select-Object -Property Name | Out-GridView -Title "All apps on destination Computer"

$Name = Read-Host -Prompt 'Input name of the application (has to be exact name)'  #name of the application
$Application = Get-WmiObject Win32_Product -ComputerName $ComputerName | Where-Object {$_.Name -eq $Name}  #choose the object, this will be the app that we will delete
if ($Application) {
  $Application.Uninstall()
  "
  
  
  
  The removal was successful"
}
else {
  $Name + ' is not installed on ' + $ComputerName
}
Start-Sleep -Seconds 10

Solution

  • There is no universal line for it, Get-Package is a god command but if you want to use remotely it becomes hard to deal with as it needs to be invoked (too many problems when sing invoke, having an administrator account isn't enough, so it defeats purpose of creating this app). I was thinking of using combination of :

    `cmd.exe /c "$($app.meta.Attributes["UninstallString"]) /S"`
    

    and

    $Application = Get-WmiObject Win32_Product -ComputerName $ComputerName | Where-Object {$_.Name -eq $Name}  #choose the object, this will be the app that we will delete
    if ($Application) {
      $Application.Uninstall()
    

    but then the issue becomes that Get-package in a properly secured domain isn't usable on remote. while WmiObject has no issues.

    I still haven't found a way to delete .EXE applications remotely using an admin account. (with PowerShell of course)

    I am new so my terminology isn't as developed as others but I think I got my point across