0
是否可以通過發佈者名稱刪除軟件?我嘗試過不同的方式來做到這一點,但我無法做到。我可以使用名稱將其刪除,但某些程序名稱不匹配,但發佈者相同。Powershell刪除已安裝的應用程序
例如
Get-WmiObject -Class Win32_Product -ComputerName $PCNumber -Filter "Publisher LIKE '%$Publisher%'" | Foreach-Object {
Write-Host
Write-Host "Uninstalling: $($_.Name)"
Write-Host
$rv = $_.Uninstall().ReturnValue
if($rv -eq 0)
{
$remove = "$drive\Program Files\software\";
if ((Test-Path "$remove")){
Remove-Item $remove -Recurse -Force
}
$remove = "$drive\Program Files (x86)\software\";
if ((Test-Path "$remove")){
Remove-Item $remove -Recurse -Force
}
Write-Host "$($_.Name) uninstalled sucessfully"
}
else
{
Write-Host "There was an error ($rv) uninstalling $($_.Name)"
}
}
我試過這個,但失敗了。
這工作正常。謝謝您的回覆。 Get-WmiObject -Class Win32_Product -ComputerName「。」 -Filter「供應商LIKE'Microsoft%'」| Foreach-Object { Write-Host Write-Host「Uninstalling:$($ _。Name)」 Write-Host } – hello 2011-12-16 08:22:01