invoke-sqlcmd

Insert data row wise in a SQL Table from a CSV using PowerShell

孤街浪徒 提交于 2019-12-01 07:48:48
问题 So I have this particular scenario where I need to insert data from multiple CSV files into multiple SQL tables . I have come across this SO link, which inserts data on a row by row basis. Below is the code-snippet from the link - Import-CSV .\yourcsv.csv | ForEach-Object {Invoke-Sqlcmd ` -Database $database -ServerInstance $server ` -Query "insert into $table VALUES ('$($_.Column1)','$($_.Column2)')" } The problem which I am facing is, I have multiple CSVs with the different number of