How to uninstall an application through powershell

Configurare noua (How To)

Situatie

You can uninstall an application using PowerShell by leveraging the Get-WmiObject cmdlet to query the Win32_Product class. Here’s an example of how you can uninstall an application:

Solutie

# Specify the name of the application you want to uninstall
$applicationName = “YourApplicationName”

# Get the product information
$application = Get-WmiObject -Query “SELECT * FROM Win32_Product WHERE Name=’$applicationName'”

# Check if the application is installed
if ($application -ne $null) {
# Uninstall the application
$application.Uninstall()
Write-Host “$applicationName has been uninstalled.”
} else {
Write-Host “$applicationName is not installed on this computer.”
}

  • Replace “YourApplicationName” with the actual name of the application you want to uninstall. Keep in mind that the Win32_Product class might not list all installed applications, and it can be slow on systems with a large number of installed products.
  • Alternatively, if you are using Windows PowerShell 5.1 or later, you can use the Get-Package and Uninstall-Package cmdlets to uninstall an application. Here’s an example:

# Specify the name of the application you want to uninstall
$applicationName = “YourApplicationName”

# Get the package information
$package = Get-Package -Name $applicationName

# Check if the application is installed
if ($package -ne $null) {
# Uninstall the application
Uninstall-Package -Name $applicationName -Force
Write-Host “$applicationName has been uninstalled.”
} else {
Write-Host “$applicationName is not installed on this computer.”
}

  • Again, replace “YourApplicationName” with the actual name of the application you want to uninstall. This method is generally faster and more efficient than using Win32_Product.
  • Keep in mind that administrative privileges might be required to uninstall certain applications, and the application may require confirmation during the uninstallation process.

Tip solutie

Permanent

Voteaza

(7 din 13 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?