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

猜你喜欢

转载自blog.51cto.com/11333879/2563066