Is it possible to remove software by the publisher name. I have tried different ways to do it but I was not able to. I can use name to remove it but some programs name doesn’t match but the publisher is same.
e.g.
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)"
}
}
I have tried this but it failed.
1 Answer