Powershell 使用已安装程序列表来获取有关特定程序的信息 [英] Powershell use list of installed programs to get information about a specific program

查看:65
本文介绍了Powershell 使用已安装程序列表来获取有关特定程序的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我已经成功地检索了我计算机上所有已安装程序的列表,并且能够使用以下代码将它们存储到一个数组中:

So I've successfully been able to retrieve a list of all the installed programs on my computer and have been able to store them into an array with the following code:

Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |  Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | 
Format-Table –AutoSize

现在我要做的是输出一个我已经完成的程序名称的列表,但允许用户输入他们想要查看更多信息的程序名称并通过一些命令,找到该程序,并仅输出该程序的属性.有什么提示吗?

Now what I am trying to do is output a list of the only the names of the programs, which I have already done, but allow the user to type in the name of the program they'd like to view more information about and have some command go through, find the program, and output the properties for ONLY that program. Any tips?

推荐答案

你并不是很具体你在寻找什么,但这会满足你提供的一点点.向用户显示名称.继续提示,直到他们不输入任何内容.对于每场比赛,我们都会向用户显示相关结果并继续提示.

You are not really specific what you are looking for but this would satisfy what little you provided. Display the names to the user. Continue prompting until they do not enter anything. For every match we display the pertinent results to the user and continue the prompt.

# Gather information
$productDetails =  Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
# Display teaser information to the user
$productDetails | Select-Object DisplayName


do {
    Write-Host "--McPrompter 5000--" -ForegroundColor Green
    $response = Read-Host "Type a partial software title or <Enter> to quit"

    # If there is text lets see if there is a match
    If($response){
        $results = $productDetails | Where-Object{$_.DisplayName -like "*$response*"}
        If($results){ 
            $results | Format-Table -AutoSize
        } Else {
            Write-Host "No match for $response. Please try again." -ForegroundColor Red
        }
    }
} until (!$response)

注意那个键

了解如果系统是 x64,您将需要检查 syswow64 密钥才能获得完整列表.您应该可以在此处或在 Google 上找到更多相关信息.

Understand that you will need to check the syswow64 key if the system is x64 to get the complete list. You should be able to find more information about that here or on the Google.

这篇关于Powershell 使用已安装程序列表来获取有关特定程序的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆