我正在编写一个从SQL Server数据库导出数据的脚本。我想输出一个分隔符为";"的.csv文件。
这是我的脚本:
#Variable to hold variable
$SQLServer = "SERVEUR"
$SQLDBName = "TOTO"
$uid ="PS"
$pwd = "password123"
$delimiter = ";"
#SQL Query
$SqlQuery = "SELECT * from $SQLDBName.dbo.SAGE_TO_PRESTASHOP;"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True;"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
#Creating Dataset
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$DataSet.Tables[0] | Out-File "E:EXPORTSexport.csv"
将您的底线替换为:
$DataSet.Tables[0] | export-csv -Delimiter $delimiter -Path "E:EXPORTSexport.csv" -NoTypeInformation