Reputation: 319
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?
Upvotes: 0
Views: 1390
Reputation: 463
You can basically try simple things, by displaying the list of Softwares and have your logic after the selection.
$Softwares = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$Choice = @{}
$Number = 1
foreach ($Software in $Softwares.DisplayName)
{
$Choice.add($Number,$Software)
$Number = $Number + 1
}
$Choice | Format-Table
[Int]$MenuChoice = read-host "Please enter your choice"
Switch($MenuChoice)
{
1{
Write-Host "Selected Software is" $Choice.get_item($MenuChoice);
#Your Logic here
}
2{
#Your Logic here
}
default{"please select a valid Software"}
}
Hope this helps!!
Upvotes: 0
Reputation: 46710
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)
Note about that key
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.
Upvotes: 1