Skip to content

Instantly share code, notes, and snippets.

@SQLvariant
Created October 10, 2019 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SQLvariant/d978f46a2bd889e16eeb08ade82e9198 to your computer and use it in GitHub Desktop.
Save SQLvariant/d978f46a2bd889e16eeb08ade82e9198 to your computer and use it in GitHub Desktop.
Basic script to import every .CSV file from a directory and INSERT each one into it's own table in SQL Server. It will create the table if it doesn't exist.
dir -Filter *.csv |
foreach {
"$($_.Name)";
,(Import-Csv -Path $_.Name) |
Write-SqlTableData -ServerInstance localhost\SQL2017 -DatabaseName BlankDB -SchemaName dbo -TableName $_.BaseName -Force
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment