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

SURESH0518
SURESH0518 used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
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
Commented:
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:

https://www.red-gate.com/simple-talk/sql/database-administration/creating-csv-files-using-bcp-and-stored-procedures/

Powershell itself doesn't have any export feature by my knowledge but you can call utilities that exist installed on the machine.
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

I think there have been enough answers already that deserve points rather than just deleting the question.
Top Expert 2014

Commented:
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.

:o)))))

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial