Zum Inhalt springen

SQL import from CSV with powershell

$SQLserver = 'server\instance'
$Path_to_exports = 'D:\Temp\SQL_Exports'
$files = Get-ChildItem -Path $Path_to_exports
 foreach ($file in $files) {
     ((Get-Content -path $file.FullName -Raw) -replace '"','') | Set-Content -Path $file.FullName 
     $DestDB = (Get-Item $file.FullName).BaseName -split '-'
     Import-DbaCsv -Path $file  -SqlInstance $SQLserver -Database $DestDB[0] -Table $DestDB[1] 
 }