0

我有一个对 sql 的查询。

$query1 = "SELECT id,in_fname,in_lname,att_app_name, FROM events    
$dataAdapter1 = New-Object System.Data.SqlClient.SqlDataAdapter
$dataAdapter1.SelectCommand = new-object System.Data.SqlClient.SqlCommand ($query1,$connString)
$commandBuilder = new-object System.Data.SqlClient.SqlCommandBuilder $dataAdapter1
$dt1 = New-Object System.Data.DataTable
[void]$dataAdapter1.fill($dt1)
$reg = $dt1

我需要做的是按“id”对结果进行分组,然后将 foreach“做某事”传递给每个组。

就像是

foreach ($group in $reg) { do something }

有人可以帮忙吗?

4

1 回答 1

0

使用Group-Objectcmdlet。

$groups = $reg | group-object -property id;
foreach ($group in $groups) {
# Do stuff
}
于 2013-10-22T16:49:51.567 回答