我正在尝试获取一组应用程序的卸载路径并卸载它们。到目前为止,我得到了卸载路径的列表。但我正在努力实际卸载这些程序。
到目前为止,我的代码是。
$app = @("msi1", "msi2", "msi3", "msi4")
$Regpath = @(
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
)
foreach ($apps in $app){
$UninstallPath = Get-ItemProperty $Regpath | where {$_.displayname -like "*$apps*"} | Select-Object -Property UninstallString
$UninstallPath.UninstallString
#Invoke-Expression UninstallPath.UninstallString
#start-process "msiexec.exe" -arg "X $UnistallPath /qb" - wait
}
这将返回以下结果:
MsiExec.exe /X{F17025FB-0401-47C9-9E34-267FBC619AAE}
MsiExec.exe /X{20DC0ED0-EA01-44AB-A922-BD9932AC5F2C}
MsiExec.exe /X{29376A2B-2D9A-43DB-A28D-EF5C02722AD9}
MsiExec.exe /X{18C9B6D0-DCDC-44D8-9294-0ED24B080F0C}
我正在努力寻找执行这些卸载路径并实际卸载 MSI。
我曾尝试使用Invoke-Expression $UninstallPath.UninstallString
,但它只显示 Windows 安装程序并为我提供 msiexec 选项。
我也尝试过使用start-process "msiexec.exe" -arg "X $UnistallPath /qb" - wait
,但这给出了同样的问题。