Windows

Windows – Get Software uninstall string with PowerShell and uninstall it

By October 20, 2021No Comments

Obtenir l’information

Pour obtenir les informations de désinstallation des logiciels installés sur Windows, nous devons récupérer les clés registre nécessaire. Autant dans le registre x86 (legacy) que dans la version x64.
Pour cela, nous allons utiliser la commande suivante :

Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall

Pour obtenir nos informations plus ciblées, nous devons récupérer les propriétés et sélectionner les propriétés à afficher :

Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty |  Select-Object -Property Displayname, UninstallString

Il est possible aussi de rechercher une application en particulier en filtrant sur le DisplayName avec la valeur désirée :

Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object {$_.DisplayName -like "Google Chr*" }|  Select-Object -Property Displayname, UninstallString

Désinstaller le ou les logiciels

Afin de désinstaller les logiciels, nous allons faire une boucle :

$GetSoftware = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall  | Get-ItemProperty | Where-Object {$_.DisplayName -like "Google Chrom*" } | Select-Object -Property DisplayName, UninstallString
	ForEach ($Software in $GetSoftware) {
		If ($Software.UninstallString) {
		$UninstallString = $Software.UninstallString
		& cmd /c $UninstallString /quiet /norestart
	}
}

<br>
Afin de désinstaller 1 logiciel:

$app = Get-WmiObject -Class Win32_Product -Filter "Name = 'YOUR_APP'"
$app.Uninstall()

Leave a Reply