Created
December 15, 2016 01:21
-
-
Save andreasbotsikas/8e23146f23166cf422d24291efc5f89a to your computer and use it in GitHub Desktop.
Export tables to csv via powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# These databases contain a dbo.VfiTagNumHistory and a dbo.VfiTagStrHistory table | |
$Database = @("VfiTag","VfiTag_0_1427961614083","VfiTag_1427961614084_1397948399843","VfiTag_1427961614084_1403650799757","VfiTag_1427961614084_1409957999664","VfiTag_1427961614084_1415401199875","VfiTag_1427961614084_1420239599988","VfiTag_1427961614084_1423609199863","VfiTag_1427961614084_1425941999989") | |
# For each database | |
$Database | foreach { | |
# export num history to csv using the bcp tool | |
$command = "cmd.exe /C ""C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\bcp.exe"" $_.dbo.VfiTagNumHistory out C:\Work\Personal\Optimus\$($_)_Num.csv /S. /c /t, -T" | |
Invoke-Expression -Command:$command | |
#export the string history to csv using the bcp tool | |
$command = "cmd.exe /C ""C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\bcp.exe"" $_.dbo.VfiTagStrHistory out C:\Work\Personal\Optimus\$($_)_Str.csv /S. /c /t, -T" | |
Invoke-Expression -Command:$command | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment