Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Exporting data with header using Powershell

By Louis Li,

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.

Total article views: 1288 | Views in the last 30 days: 1
 
Related Articles
FORUM

Monitoring script

script

FORUM

Script

Need Automated Script

FORUM

drop script

drop script

FORUM

Script component

Script component

 
Contribute