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

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.
SURESH0518Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Elliott ClarkDBACommented:
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
0
aikimarkCommented:
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
0
ZberteocCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

ZberteocCommented:
I think there have been enough answers already that deserve points rather than just deleting the question.
0
aikimarkCommented:
I think the points should be split:
80% #a42359337
20% #a42359292
0
ZberteocCommented:
Somebody accepted the proposal for the points split as the correct answer! Probably who posted it.

:o)))))
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.