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
select * from sys.master_files
Run: .\csv.ps1 . master master.sql
2 csv files will be generated:
They contain results from these 2 queries.