I find I need to save C# DataTables to CSV files often and as such use the following code:
These two functions below have saved me a lot of time, you simply create a class with variables inside it and then pass said class to the two functions below:
PowerShell has a module to assist with this, you can find out all the specifics at https://docs.microsoft.com/en-us/sql/powershell/download-sql-server-ps-module. I was asked to pull data and export it to a CSV to save time, which is easy to do with Task Scheduler and PowerShell.
The more I use power shell the more I realize you can do just about anything you could do with visual studio and C#. I haven’t found a comprehensive source for all the little differences between C# and powershell but the following are some things to take note of: