我已经走到这一步了,但是它删除了SAP的所有版本,我只想删除某些版本。我已尝试更改我要搜索的内容,但仍会删除SAP的所有版本
$y = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |
Get-ItemProperty |
Where-Object {$_.DisplayName -match 'SAP Netweaver Business Client 3.5' } |
Select-Object -Property DisplayName, UninstallString, PSPath
foreach ($x in $y)
{
if ($x.UninstallString)
{
$uninst = "C:\Program Files (x86)\SAP\SapSetup\Setup\nwsapsetup.exe"
Start-Process $uninst -ArgumentList "/uninstall /nodlg /force"
}
}发布于 2016-07-01 01:05:14
最终脚本
这将删除Netweaver的所有版本。这不是我的功劳,因为我的同事创造了这个。
$y = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |
Get-ItemProperty |
Where-Object {$_.DisplayName -match "SAP Netweaver Business Client" -and $_.Publisher -match "SAP AG" } |
Select-Object -Property DisplayName, UninstallString, PSPath
foreach ($x in $y) {
if ($x.UninstallString -like "MsiExec.exe*") {
$x.UninstallString = $x.UninstallString -replace "/i","/x" #replace /i with /x to ensure uninstall command is executed
$x.UninstallString = $x.UninstallString -replace "MsiExec.exe ","" #remove MsiExec.exe so that only arguements are left
$x.UninstallString = "$($x.UninstallString) /qn" #append the /qn for silent uninstall
Start-Process -filepath "MsiExec.exe" -ArgumentList "$($x.UninstallString)" -Wait -WindowStyle Hidden
} else {
#check to see if the UninstallString contains quotes
$x.UninstallString = "$($x.UninstallString) /nodlg"
Start-Process cmd.exe -ArgumentList "/c `"$($x.UninstallString)`"" -WindowStyle Hidden -Wait
write-host "$($x.displayname) uninstalled"
}
} https://stackoverflow.com/questions/38124186
复制相似问题