我想使用PowerShell将日志文件导入sql表。有没有人这样做? 日志底部有一些结构,但我想跳过前13行。
示例日志:https://lh6.googleusercontent.com/yFajtwkfT73JqojMiEZMz-_1cy6XQlHtqP5ibkJbfpM=w484-h228-p-no
SQL连接的Powershell脚本:
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server=Server\Development;Database=Development;Integrated Security=True"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = "BULK INSERT Development..CUBE_LOG
FROM 'D:\POWERCUBE_SQL_LOG\result.txt'
WITH (CODEPAGE='RAW' ,FIELDTERMINATOR = '|',ROWTERMINATOR = '\n', DATAFILETYPE='widechar')"
$SqlCmd.Connection = $SqlConnection
$SqlConnection.Open()
$sqlCmd.ExecuteNonQuery()
$SqlConnection.Close()
答案 0 :(得分:0)
在批量插入中使用第一行参数。
参考:http://technet.microsoft.com/en-us/library/ms188365.aspx
WITH (CODEPAGE='RAW' ,FIELDTERMINATOR = '|',ROWTERMINATOR = '\n',FIRSTROW = 14,DATAFILETYPE='widechar')"