Invoke-SqlCmd is kind of a PITA. I've always just used .NET. Create a System.Data.Sql.SqlConnection, connect it to a SqlCommand with the query, execute the query and get a DataReader back. Enumerate the DataReader. If you look at our free ebook on building historical and trend reports (it's in the eBooks menu, here), you can see the 4-5 lines of code it takes to do that in the various examples.