Powershell删除已安装的应用程序

发布于 2024-12-21 09:10:10 字数 850 浏览 2 评论 0原文

是否可以通过发布者名称删除软件。我尝试过不同的方法来做到这一点,但我没能做到。我可以使用名称来删除它,但有些程序名称不匹配,但发布者是相同的。

例如

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

我已经尝试过但失败了。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伪装你 2024-12-28 09:10:10
$products = gwmi -class win32_product -filter "Vendor like 'Microsoft%'"
if ($products) {
    foreach ($product in $products) {
        $product
        # Processing here...
    }
}
$products = gwmi -class win32_product -filter "Vendor like 'Microsoft%'"
if ($products) {
    foreach ($product in $products) {
        $product
        # Processing here...
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文