powershell - 如何检查是否安装了特定的MSI?

标签 powershell

我正在编写一个Powershell脚本,该脚本将为我的Web应用程序安装一些依赖项。在我的脚本中,我经常遇到检查是否安装了特定应用程序的问题。似乎有一种独特的方法来检查每个应用程序是否存在一个应用程序(即:通过检查此文件夹或c:上该文件的存在)。是否无法通过查询已安装的应用程序列表来检查是否已安装应用程序?

最佳答案

这是我有时使用的代码(不太常用,所以...)。有关详细信息,请参见帮助注释。

<#
.SYNOPSIS
    Gets uninstall records from the registry.

.DESCRIPTION
    This function returns information similar to the "Add or remove programs"
    Windows tool. The function normally works much faster and gets some more
    information.

    Another way to get installed products is: Get-WmiObject Win32_Product. But
    this command is usually slow and it returns only products installed by
    Windows Installer.

    x64 notes. 32 bit process: this function does not get installed 64 bit
    products. 64 bit process: this function gets both 32 and 64 bit products.
#>

function Get-Uninstall
{
    # paths: x86 and x64 registry keys are different
    if ([IntPtr]::Size -eq 4) {
        $path = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
    }
    else {
        $path = @(
            'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
            'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
        )
    }

    # get all data
    Get-ItemProperty $path |
    # use only with name and unistall information
    .{process{ if ($_.DisplayName -and $_.UninstallString) { $_ } }} |
    # select more or less common subset of properties
    Select-Object DisplayName, Publisher, InstallDate, DisplayVersion, HelpLink, UninstallString |
    # and finally sort by name
    Sort-Object DisplayName
}

Get-Uninstall

关于powershell - 如何检查是否安装了特定的MSI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4753051/

相关文章:

linux - 我如何在 linux 上对字符串进行 base64 编码,使其与 windows "Unicode.GetBytes.ToBase64String"匹配?

powershell - 如何在cmd/c中设置%ERRORLEVEL%?

azure - 获取具有自定义属性的 Azure AD B2C 用户表

powershell - 搜索邮箱SearchQuery不起作用

azure - 存储 blob 删除批量删除除两个具有相似名称的目录之外的所有 blob

powershell - 在 Powershell 中第二个句点后获取文本的子字符串

PowerShell 希望在 TeamCity 中进行提示

powershell - 如何从阵列中删除 powershell

PowerShell脚本读取文件的性能太慢

powershell - 如何从列表中异步调用多个 URL