How to save data from all tables in SQL Server database into CSV files (using PowerShell)

  • Posted on: 23 September 2015
  • By: Michał Turecki

All it takes is to create the following PowerShell script (text file with .ps1 extension) and changing $server and $db variables to match the server's host and instance name (SERVER\INSTANCE) and a database name.

$destDir = Get-Location
$server = "localhost"
$db = "DatabaseToExport"

Import-Module -Name SQLPS
$tables = Invoke-Sqlcmd -query "SELECT name FROM sys.tables" -Database "$db" -ServerInstance "$server"
foreach ($table in $tables)
{
	$tableName = $table["name"]
	write-host -ForegroundColor Green "Creating File $tableName.csv"
	Invoke-Sqlcmd -Query "SELECT * FROM $tableName;" -Database "$db" -Server "$server" |
		Export-Csv -NoTypeInformation -Path "$destDir\$tableName.csv" -Encoding UTF8
}

Comments

Cialis Prezzo Ufficiale Acheter Cialis Sur Ordonnance

Cialis Prezzo Ufficiale Acheter Cialis Sur Ordonnance

buy now isotretinoin - isotretinoin cash delivery Vente Cialis 5 Mg viagra Autorizza Il Kamagra Г€ In Francia Viagra E Utilizzo Propecia Long Term Effects

buy now isotretinoin - isotretinoin cash delivery Vente Cialis 5 Mg viagra Autorizza Il Kamagra Г€ In Francia Viagra E Utilizzo Propecia Long Term Effects

buy now isotretinoin - isotretinoin cash delivery Vente Cialis 5 Mg viagra Autorizza Il Kamagra Г€ In Francia Viagra E Utilizzo Propecia Long Term Effects

buy now isotretinoin - isotretinoin cash delivery Vente Cialis 5 Mg viagra Autorizza Il Kamagra Г€ In Francia Viagra E Utilizzo Propecia Long Term Effects

Canadian Pharmacies Top Best Cialis Generic Forum cheapest cialis Comprar Cialis Generico Sin Receta Kamagra Gelatina 100mg

Canadian Pharmacies Top Best Cialis Generic Forum cheapest cialis Comprar Cialis Generico Sin Receta Kamagra Gelatina 100mg

Amlodipine Besylate Levitra Se Puede Comprar Sin Receta Viagra Costo A Confezione cialis prices L'Ejaculation Rapide Viagra Achat Net Achat Slimex 15 Mg

Best Canadian Pills cialis without prescription Achat Cialis Canada Compra Viagra Generico

Best Canadian Pills cialis without prescription Achat Cialis Canada Compra Viagra Generico

Propecia Finasteride Cost Cilais And Priligy generic viagra Fish Amoxicillin Sales Viagra Products Online

Is 25mg Viagra Enough Comment Acheter Cytotec Sans Ordonnance Great Online Pharmacy viagra Cialis Cost Per Pill Buy Wellbutrin Without A Perscrition Levitra Horsturz

Is 25mg Viagra Enough Comment Acheter Cytotec Sans Ordonnance Great Online Pharmacy viagra Cialis Cost Per Pill Buy Wellbutrin Without A Perscrition Levitra Horsturz

Is 25mg Viagra Enough Comment Acheter Cytotec Sans Ordonnance Great Online Pharmacy viagra Cialis Cost Per Pill Buy Wellbutrin Without A Perscrition Levitra Horsturz

Vendo Cialis Generico Madrid horaires levitra Acheter Du Cialis Propecia Kvinder Generic Propecia Successful

Vendo Cialis Generico Madrid horaires levitra Acheter Du Cialis Propecia Kvinder Generic Propecia Successful

Vendo Cialis Generico Madrid horaires levitra Acheter Du Cialis Propecia Kvinder Generic Propecia Successful

Orlistat Effets Secondaires cheapest cialis 20mg Propecia Shop Levitra Paypal Accepted Cialis Es Mejor Que El Viagra

Atenolol And Amoxicillin Cheap Xenical Online Australia Levitra Espanol order cialis online Diabetes Y Kamagra

Pharmacy Clomid Ne Marche Pas п»їcialis Can You Buy Orlistat

Kamagra Viagra Erfahrungsberichte viagra online Doxycycline Monohydrate Canada Mail Order Fluoxetine

Kamagra Viagra Erfahrungsberichte viagra online Doxycycline Monohydrate Canada Mail Order Fluoxetine

What Bacteria Does Amoxicillin Kill acheter cialis 20mg en pharmacie Buy Aldara Cream India Buy Clomiphene And Gonadotropins

What Bacteria Does Amoxicillin Kill acheter cialis 20mg en pharmacie Buy Aldara Cream India Buy Clomiphene And Gonadotropins

What Bacteria Does Amoxicillin Kill acheter cialis 20mg en pharmacie Buy Aldara Cream India Buy Clomiphene And Gonadotropins

What Bacteria Does Amoxicillin Kill acheter cialis 20mg en pharmacie Buy Aldara Cream India Buy Clomiphene And Gonadotropins

Canadian Pills Buy Propranolol 40mg Keflex Pregnant generic cialis canada Buying Viagra In Canada Foro Kamagra Paypal

Canadian Pills Buy Propranolol 40mg Keflex Pregnant generic cialis canada Buying Viagra In Canada Foro Kamagra Paypal

Buying Prednisolone Uk Cephalexin Breast Feeding Prix Kamagra Avec Ordonnance generic cialis overnight delivery Discount Doryx Cialis 20 Mg Diabete

Le Cialis Efficace Ou Acheter Cialis Serieux Predisone Without Prescription viagra Cialis Ricetta Rossa Baclofene Arret Cigarette

Le Cialis Efficace Ou Acheter Cialis Serieux Predisone Without Prescription viagra Cialis Ricetta Rossa Baclofene Arret Cigarette

Tadalis Sx En France En Ligne viagra Avis Achat Viagra Ligne

Tadalis Sx En France En Ligne viagra Avis Achat Viagra Ligne

2275 93 Amoxicillin cialis Amoxicillin 850mg Side Effects

2275 93 Amoxicillin cialis Amoxicillin 850mg Side Effects

2275 93 Amoxicillin cialis Amoxicillin 850mg Side Effects

Cialis 20 Mg Filmtabl 12 St cialis tablets for sale Zithromax At Walmart Venta Viagra Valencia

Cialis 20 Mg Filmtabl 12 St cialis tablets for sale Zithromax At Walmart Venta Viagra Valencia