This was a massively hard concept for me to grasp when I first ran into it as well.
There are some complexities that the more technically eloquent can speak to; but a decent conceptual starting point is that your SQL request returns an ad-hoc array, so powershell doesn't know what to do with it when you try to treat it as a table.

Once you've done this $myOut can be sorted, converted to csv, etc.
My standard usage is to

convert-tohtml -as table

and then insert it into the body of an email.

Please note there are several ways of turning those array results into your own custom object, and there are some reasons to use splatting rather than add-member... but for myself personally I find this layout really easy and accurate to modify when I use it as a template.

Hope that helps

Author

Posts

The topic ‘Execute SQL Stored Procedure and export results to CSV’ is closed to new replies.