0

参考:[ https://dbatools.io/functions/import-dbacsvtosql/]

尝试使用 DBA 工具将一些信息影响到 SQL Server 中,当我尝试导入时出现错误 - 脚本的其余部分工作正常,除了Import-csv

Import-DbaCsvToSql :“++”运算符仅适用于数字。操作数是“System.IO.FileInfo”。在行:5 字符:5

我用来导出和导入的查询是:

$query2 = "select * from "+" $($_.Table1ToKeep)"
$ExportFile = "\\Server\e$\DatabaseNameTable2Keep\"+"$($_.Table1ToKeep)_$($_.TrgServer)"+".csv"

Invoke-Sqlcmd2 -serverinstance $_.TrgServer -database $_.DataBaseName -Query $query2 | Export-CSV -Path $ExportFile -Delimiter "|" -NoTypeInformation 

$fileList = Get-ChildItem \\ServerName\e$\DatabaseNameTable2Keep\ -Filter *.csv
foreach ($i in $fileList){
    (Get-Content -Path $i.FullName ) -replace '"' , '' | Set-Content -Path $i.FullName
}

Import-DbaCsvToSql -Csv "\\ServerName\e$\DatabaseNameTable2Keep\$($_.Table1ToKeep)_$($_.TrgServer).csv" -SqlInstance Instance01 -Database DatabaseName -Table "$($_.Table1ToKeep)_$($_.TrgServer)"  -Delimiter "`|" -FirstRowColumns 

谢谢

4

0 回答 0