在Powershell中加入两个结果

Hin*_*nek 6 powershell cmdlets join

我有两个返回对象列表的CMDlet.一个返回SPSolution类型的对象,其中包含属性Id,另一个返回SPFeature类型的对象,其属性为SolutionId.

现在我想加入/合并这样的数据:

$f = Get-Feature
$s = Get-Solution
$result = <JOIN> $f $s
          <ON> $f.SolutionId = $s.Id
          <SELECT> FeatureName = $f.DisplayName, SolutionName = $s.Name
Run Code Online (Sandbox Code Playgroud)

Dam*_*ell 5

它没有效率,它假定PowerShell 2但它应该做的工作:

$solutions = Get-Solution

foreach ($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
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

请注意,我没有安装SharePoint,所以我担心我无法测试这个!