Powershell Scirpt :Copy data from MS SQL Server DB to CSV file

Hello Team,

I am looking for powershell script to copy the data from MS SQL Server DB table(TABLE1) and need to store the data in the CSV file and copy in the local system.
Please advise.

Regards
RK

Have you searched for this? It can be very simple with pre-built SQL modules, but you need SQL Management Studio installed on the server\machine running the Powershell script. If you want no dependencies, it’s still possible, just a bit more code. The articles below explain the pros\cons of approaches as well as dependencies.

Getting Data out of SQL Server from Powershell – SQLServerCentral

Getting Data out of SQL Server from Powershell – SQLServerCentral

Once you have the data, you just use Export-Csv to create the csv.

2 Likes