Powershell删除已安装的应用程序

时间:2011-12-15 11:25:33

标签: powershell powershell-v2.0 powershell-remoting

是否可以按发布商名称删除软件。我尝试过不同的方法,但我无法做到。我可以使用名称删除它,但某些程序名称不匹配,但发布者是相同的。

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)"
    }
}

我试过了,但失败了。

1 个答案:

答案 0 :(得分:0)

$products = gwmi -class win32_product -filter "Vendor like 'Microsoft%'"
if ($products) {
    foreach ($product in $products) {
        $product
        # Processing here...
    }
}