Extract data from System.Data.DataRow in powershell
Assuming the column name is GroupID
$sql = "SELECT [GroupID] FROM theTable"
$table = Invoke-SQLCmd -Query $sql -ServerInstance $sqlServerInstance -Database $database -OutputAs DataRows
foreach($user_info in $table)
{
$user_info.GroupID
}
or
foreach($user_info in $table.GroupID)
{
$user_info
}
You can also use ItemArray. Prints the entire row, while Item(index) prints the values from the indexed cell.
Item
is a parameterized property, not a list you can index into:
foreach($row in $table)
{
$row.Item("GroupID")
}
or (assuming that "GroupID" is the first column):
foreach($row in $table)
{
$row.Item(0)
}