Reference: [https://dbatools.io/functions/import-dbacsvtosql/]
Trying to impact a few information into SQL Server using DBA Tools, and I get the error when I attempt to import - The rest of the script works fine, except for the Import-csv
:
Import-DbaCsvToSql : The '++' operator works only on numbers. The operand is a 'System.IO.FileInfo'. At line:5 char:5
Query I am using to export and import is:
$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
Thanks