We help IT Professionals succeed at work.

What is the fastest to export output of a storedprocedure to a csv file using PowerShell

SURESH0518 asked
I have a SQL SERVER Stored procedure and it takes 4 minutes and output of this stored procedure is around 700k. WHat is fastest way to export to CSV using PowerShell. Any help is appreciated.
Watch Question

There's not much detail in your question, therefore I'll assume you just want to know the PowerShell command to export to CSV

Export-Csv c:\temp

Open in new window

at the end of your script and change the location to wherever you wish to CSV file to be exported to
Top Expert 2014
Have the PS script invoke an SSIS function to do the export directly from SQL Server.  Don't process any of the data with PS code
The fastest way to export anything from SQL server to a CSV file, PowerShell or not, is using the BCP utility. Here is an article that shows you in detail how to export from a stored procedure:


Powershell itself doesn't have any export feature by my knowledge but you can call utilities that exist installed on the machine.
I think there have been enough answers already that deserve points rather than just deleting the question.
Top Expert 2014

I think the points should be split:
80% #a42359337
20% #a42359292
Somebody accepted the proposal for the points split as the correct answer! Probably who posted it.