1. Save this script (e.g. csv.ps1)
2. Run .\csv.ps1 <server name> <database name> <SQL script file>
Output files will be generated under same folder this PowerShell script is in.
Note: In SQL Script file, multiple statements can be added and they will be saved into files sequentially. Filenames are sequential numbers.
For example, master.sql:
select * from sys.configurations
go
select * from sys.master_files
go
Run: .\csv.ps1 . master master.sql
2 csv files will be generated:
1.csv
2.csv
They contain results from these 2 queries.