1

我正在编写一个脚本来使用 msiexec 自动修复软件。我遇到的问题是,当我打电话时:

get-wmiobject -class win32_product -filter "name of software" | foreach-object {$_.IdentifyingNumber}

解析每个产品编号所需的时间接近 5-10 分钟。有没有更快的方法来做到这一点?

4

1 回答 1

0

正如 Lee_Dailey 所提到的,您可以从注册表中的卸载键中获取此信息。

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

以下将为您提供使用卸载键中的条目安装的应用程序的名称和 GUID。-match "^{.+}$"仅返回以 开头{和结尾的条目}。如果您想要不带大括号的 GUID 输出,{}则可以将其强制转换为[GUID],例如[GUID][String]$matches.Values.

Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |
%{
    if(($_.Name | Split-Path -Leaf) -match "^{.+}$")
    {
        [PSCustomObject]@{
            GUID = [String]$matches.Values
            Name = [String]($_ | Get-ItemProperty -ErrorAction SilentlyContinue).DisplayName
        }
    }
}

输出:

GUID                                   Name                                                          
----                                   ----                                                          
{0CA4BB37-FF4A-42C6-A39C-11CB0BB8D395} Microsoft .NET Core Host - 2.1.8 (x64)                        
{1657ABEE-7D56-416A-B7E0-A89CC5AAD0F7} Microsoft Azure Compute Emulator - v2.9.6 
...
于 2019-04-20T11:35:22.083 回答