How to iterate through a get-sqldata resultset

rated by 0 users
This post has 2 Replies | 2 Followers

Top 500 Contributor
Posts 10
stiej1977 Posted: 11-01-2011 6:26 AM

how do i iterate through a resultset obtained from using the SQLPSX get-sqldata? I want to output the resultset to an excel file. i'm ok with creating the excel file.


Top 10 Contributor
Posts 658
Idera Employee

SQLPSX get-sqldata returns an ADO.Net DataTable. One way to iterate we be to use a ForEach like this:

$tbl = get-sqldata ...

foreach ($row in $tbl) {




Enclosing the field in a $( ) ensures you get the underlying data primitive.

Top 500 Contributor
Posts 10

That's what I wanted to hear! thanks so much. I've spent hours and hours messing round with different ways. just couldn't work out why $row.Field by itself didn't work. Didn't know about this $(....) thing.


thanks a lot


Page 1 of 1 (3 items) | RSS
Copyright 2012 All rights reserved.