Powershell 通過UninstallString 卸載軟件

通過Powershell 來卸載軟件, 需要先找到軟件列表的UninstallString 存儲信息, 查找方法查找Uninstall註冊表路徑來進行搜索

32位查找路徑: HKLM:\SOFTWARE\Microsoft\Microsoft\Windows\CurrentVersion\Uninstall\*

64位查找路徑:HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*

之後根據UninstallString 的結果來運行卸載程序, 這個時候就需要藉助MsiExec  工具來執行卸載過程了

通過MsiExec 來卸載軟件微軟官網給了很清晰的解釋,但是按照文檔去嘗試, 始終沒有成功, 在自己的一次次失敗當中記錄下成功的命令格式如下:

最後再稍微進行調整, 執行成功

MsiExec.exe /x "{6D4839CB-28B4-4070-8CA7-612CA92CA3D0}" /q

以下是完整執行過程

$apps = Get-ChildItem 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' |Get-ItemProperty |?{$_.Publisher -eq "12344"}
$uninstallstrings = $apps |select DisplayName,UninstallString
$uninstallcmd = $uninstallstrings[1].UninstallString.Replace('{','"{').replace('}','}"') + ' /q'
Invoke-Expression $uninstallcmd

多次的嘗試, 區別在於使用了雙引號, 但是不知所以...

MsiExec 官方文檔介紹

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/msiexec

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章