windows - How to uninstall an application using PowerShell?

Windows - How to uninstall an application using PowerShell?

To uninstall an application using PowerShell on Windows, you can use the Get-WmiObject cmdlet to query for the installed application and then invoke its uninstall method. Here's a step-by-step guide:

Step-by-Step Guide

  1. Identify the Application Name or GUID:

    • Before uninstalling, you need to know the exact name or GUID (Globally Unique Identifier) of the application you want to remove. This information is typically found in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall.
  2. Open PowerShell:

    • Open PowerShell with administrative privileges. Right-click on the PowerShell icon and select "Run as administrator" to ensure you have the necessary permissions to uninstall software.
  3. Uninstall the Application:

    • Use the Get-WmiObject cmdlet to locate and uninstall the application. Replace ApplicationName with the name or GUID of the application you wish to uninstall.
    # Replace 'ApplicationName' with the actual name or GUID of the application
    $appName = 'ApplicationName'
    
    # Find the application by Name or GUID and uninstall
    $app = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -eq $appName }
    $app.Uninstall()
    
    • Alternatively, you can use the Uninstall-WindowsFeature cmdlet for Windows features and roles.
    Uninstall-WindowsFeature -Name 'ApplicationName'
    

Example: Uninstalling a Sample Application

Let's say you want to uninstall an application named "ExampleApp":

# Find and uninstall application named 'ExampleApp'
$app = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -eq 'ExampleApp' }
$app.Uninstall()

Notes:

  • Name vs. GUID: The -eq operator in Where-Object can match either the application name or the GUID depending on what you have.

  • Administrative Privileges: PowerShell must be run with administrative privileges (Run as administrator) to successfully uninstall applications.

  • Handling Errors: PowerShell might throw errors if the application is not found or if there are issues during the uninstallation process. Ensure to handle exceptions or errors appropriately in your script.

  • Alternative Methods: In some cases, applications may not be listed in Win32_Product class due to various reasons (e.g., MSI-based installations, applications not registered properly). In such cases, you might need to use different methods or utilities specific to that application's uninstallation process.

By following these steps, you can effectively uninstall applications using PowerShell on Windows, providing a scriptable and efficient way to manage software installations across multiple systems. Adjust the script based on your specific application's name or GUID and handle any errors or edge cases as needed.

Examples

  1. How to uninstall an application using PowerShell on Windows?

    Description: This query addresses the basic steps to uninstall an application using PowerShell cmdlets.

    # Uninstall an application using its name
    $appName = "AppName"
    Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -eq $appName } | ForEach-Object { $_.Uninstall() }
    
  2. How to uninstall a program using its GUID in PowerShell?

    Description: This query explains how to uninstall a program using its unique GUID.

    # Uninstall an application using its GUID
    $appGUID = "{GUID-OF-THE-APPLICATION}"
    $uninstallKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$appGUID"
    $uninstallString = (Get-ItemProperty $uninstallKey).UninstallString
    Start-Process "cmd.exe" -ArgumentList "/c", $uninstallString -Wait
    
  3. How to force uninstall an application using PowerShell?

    Description: This query addresses how to force uninstall an application using PowerShell.

    # Force uninstall an application
    $appName = "AppName"
    Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -eq $appName } | ForEach-Object { $_.Uninstall() }
    
  4. How to uninstall multiple applications using PowerShell?

    Description: This query covers uninstalling multiple applications in one script using PowerShell.

    # Uninstall multiple applications
    $appNames = @("AppName1", "AppName2", "AppName3")
    foreach ($appName in $appNames) {
        Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -eq $appName } | ForEach-Object { $_.Uninstall() }
    }
    
  5. How to uninstall a Windows Store app using PowerShell?

    Description: This query explains how to uninstall a Windows Store app using PowerShell.

    # Uninstall a Windows Store app
    $appPackageName = "Microsoft.WindowsCalculator"
    Get-AppxPackage -Name $appPackageName | Remove-AppxPackage
    
  6. How to uninstall applications on remote computers using PowerShell?

    Description: This query covers uninstalling applications on remote computers using PowerShell.

    # Uninstall applications on a remote computer
    $remoteComputer = "RemotePCName"
    $appName = "AppName"
    Invoke-Command -ComputerName $remoteComputer -ScriptBlock {
        Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -eq $using:appName } | ForEach-Object { $_.Uninstall() }
    }
    
  7. How to get a list of installed applications using PowerShell?

    Description: This query addresses getting a list of all installed applications using PowerShell.

    # Get a list of installed applications
    Get-WmiObject -Class Win32_Product | Select-Object -Property Name, Version
    
  8. How to uninstall an application with a specific version using PowerShell?

    Description: This query covers uninstalling an application with a specific version using PowerShell.

    # Uninstall an application with a specific version
    $appName = "AppName"
    $appVersion = "1.0.0"
    Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -eq $appName -and $_.Version -eq $appVersion } | ForEach-Object { $_.Uninstall() }
    
  9. How to silently uninstall an application using PowerShell?

    Description: This query explains how to silently uninstall an application using PowerShell.

    # Silently uninstall an application
    $appName = "AppName"
    $uninstallPath = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$appName").UninstallString
    Start-Process "cmd.exe" -ArgumentList "/c", "$uninstallPath /quiet" -Wait
    
  10. How to log uninstallation details using PowerShell?

    Description: This query covers how to log the details of the uninstallation process using PowerShell.

    # Log uninstallation details
    $appName = "AppName"
    $logFile = "C:\UninstallLog.txt"
    $app = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -eq $appName }
    if ($app) {
        $app.Uninstall() | Out-File -FilePath $logFile -Append
        Add-Content -Path $logFile -Value "$appName uninstalled successfully."
    } else {
        Add-Content -Path $logFile -Value "$appName not found."
    }
    

More Tags

request-timed-out touchpad math observable android-viewbinding distutils file-uri .net-core reportviewer robo3t

More Programming Questions

More Pregnancy Calculators

More Financial Calculators

More Physical chemistry Calculators

More Biology Calculators