我试图以表格格式显示我的查询结果,因此标题只显示在顶部一次,而数据显示在它下方。下面的代码重复创建的每一行的标题。使用FT-Auto时有办法解决这个问题吗? TIA
示例输出:
Name Number of computers Package advertised Success Remaining computers
CH 19 0 0 19
foreach ($ou in $ou_l)
{
$cmplist=get-adcomputer -Filter "cn -like '*L'" -searchbase $ou.distinguishedname -Properties memberof
$testcmplist=$cmplist | where {$_.memberof -like "*Test(P)*"}
$NOTcmplist=$cmplist | where {$_.memberof -ne "Test(P)"}
$pkgadv=$cmplist | where {$Members -LIKE $_.Name}
$ou| select Name,
@{n="Number of computers";e={$cmplist.count}},
@{n="Package advertised";e={$testcmplist.count }},
@{n="Success";e={$pkgadv.Count }},
@{n="Remaining computers";e={$NOTcmplist.count }} | ft -auto
}
答案 0 :(得分:1)
应该像将此格式表调用移动到ForEach循环之外一样简单
$ou_l | ForEach-Object {
$ou = $_
$cmplist=get-adcomputer -Filter "cn -like '*L'" -searchbase $ou.distinguishedname -Properties memberof
$testcmplist=$cmplist | where {$_.memberof -like "*Test(P)*"}
$NOTcmplist=$cmplist | where {$_.memberof -ne "Test(P)"}
$pkgadv=$cmplist | where {$Members -LIKE $_.Name}
$ou | Select Name, `
@{n="Number of computers";e={$cmplist.count}}, `
@{n="Package advertised";e={$testcmplist.count }}, `
@{n="Success";e={$pkgadv.Count }}, `
@{n="Remaining computers";e={$NOTcmplist.count }}
} | Format-Table -AutoSize
正如您所写的那样,每条记录都将被格式化为一个单独的表格,而不是经过调整的记录列表。