除了win32_product之外,是否有更快的方法来查找已安装软件的产品编号

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

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

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

解析每个产品编号所需的时间将近5-10分钟。有更快的方法吗?

powershell winapi get-wmiobject
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 
...
© www.soinside.com 2019 - 2024. All rights reserved.