当代码也这么说时,Powershell 脚本不会删除 Chrome

问题描述 投票:0回答:1

在我的 powershell 代码中,它的任务是删除 google crhome。该代码可以编译,但它指出 PC 上未安装 Google Chrome。但是,PC 上安装了 Google Chome。我不明白为什么它没有被认可。知道下一步该做什么吗?

# Define the application name
$appName = "Google Chrome"

# Get the application details from the registry
$app = Get-WmiObject -Query "SELECT * FROM Win32_Product WHERE Name = '$appName'"

if ($app) {
    Write-Output "Uninstalling $appName..."

    # Uninstall the application
    $app.Uninstall() | Out-Null

    if ($?) {
        Write-Output "$appName has been successfully uninstalled."
    } else {
        Write-Output "Failed to uninstall $appName."
    }
} else {
    Write-Output "$appName is not installed on this machine."
}
windows powershell if-statement select
1个回答
0
投票

也许名称有点不同,首先尝试显示所有类似“chrome”的应用程序,看看你在处理什么:

$var = Get-WmiObject win32_product | ? {$_.name -like '*chrome*'); $var
© www.soinside.com 2019 - 2024. All rights reserved.