Skip to content
Advertisement

SQL extract data to Excel using Powershell

I want to extract data from SQL server to a new excel file using powershell . For small data set my code works but some tables has more than 100.000 rows and this will take ages. The reason why I don’t use the utility in SQl server is because I want to extract mutilple tables. Is there a way to optimize my script to export big tables to excel? or is there another way to do this?

I’m using the following script

Advertisement

Answer

There’s some simple magic to make this a lot easier, and that’s Copy/Paste. What you can do is convert your datatable to a tab delimited CSV, copy that to the clipboard, and paste it into Excel. I’ll ignore your SQL part, since you seem to have that well in hand.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement