将列添加到现有的PowerShell输出

时间:2016-09-08 15:19:55

标签: sql powershell

enter image description here

请帮我解决以下问题。

$emp = $Result | select name,employer | Format-Table -AutoSize

我创建了一个函数aghealth(),它给出了一些价值。

如何将aghealth的值添加到$emp

1 个答案:

答案 0 :(得分:0)

您可以循环遍历$Results中的值并添加AGHealth值。如果此函数将$Results值中的一个作为输入,那就太好了。否则你可以使用索引到数组中(假设它返回一个数组......)

$i = 0
foreach($Result in $Results){

    [array]$actualResults += New-Object psobject -Property @{

        "Name"      = $Result.Name
        "Employer"  = $Result.Employer

        # I don't know which of these is most suitable as no idea how aghealth works
        # This will not work with duplicates so 2 of these have to go.
        "AGHealth"  = aghealth($Result.Name)
        "AGHealth"  = aghealth($Result.Employer)
        "AGHealth"  = $someVariableThatAlreadyHasAGHealthResults[$i]

    }

    $i++
}

$actualResults | Format-Table