Join two results in Powershell Join two results in Powershell powershell powershell

Join two results in Powershell


It's not efficient, and it assumes PowerShell 2 but it should do the job:

$solutions = Get-Solutionforeach ($f in Get-Feature) {    $filteredSolutions = $solutions |        where-object { $_.Id -eq $f.SolutionId }    foreach ($s in $filteredSolutions) {        new-object PSObject -prop @{            FeatureName = $f.DisplayName            SolutionName = $s.Name        }    }}

Note that I don't have SharePoint installed so I'm afraid that I can't test this!


Building off what Keith Hill saidMaking it a 2 liner can greatly improve efficiency. This way you only run Get-Solution once instead of again for every object returned by Get-Feature

$Solutions = Get-SolutionGet-Feature | % {$f = $_; $Solutions | ? {$f.SolutionId -eq $_.Id} |                  Select Name,@{n='FeatureName';e={$f.DisplayName}}}


Here's a one-liner that should do the trick (relies on nested pipelines):

Get-Feature | % {$f = $_; Get-Solution | ? {$f.SolutionId -eq $_.Id} |                  Select Name,@{n='FeatureName';e={$f.DisplayName}}}