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.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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

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
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

I think there have been enough answers already that deserve points rather than just deleting the question.
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.

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

From novice to tech pro — start learning today.