1

I have multiple remote machines on a network that have a csv file on them stored in the same location that has been created by a powershell script.

Whats the best way to insert that data into a Microsoft Sql Server express database?

5
  • Depends on the dbms product used... Commented Nov 5, 2015 at 8:39
  • Microsoft Sql Server express Commented Nov 5, 2015 at 8:40
  • Which version of SQL Server Express? Could you please paste a portion of your CSV? Are these files identically in structure on all machines? Are the of identical structure in all lines? Commented Nov 5, 2015 at 8:49
  • I am using Microsoft SQL Server Express with Visual Studio Community 2015. Commented Nov 5, 2015 at 9:05
  • Sample code isSystemSyncTime SystemSyncDate ComputerName 18:57:32 05-11-15 MINO Commented Nov 5, 2015 at 9:05

1 Answer 1

0

One way of doing this is to collect all the CSV-files from all the servers to your script server. And then run the SQL INSERT query from the script server to put your data in an SQL table.

As described in one of my previous answers you can use this module Invoke-SQLCmd2 to do this.

The other way, when you don't want to collect all the CSV-files first, is running the SQL INSERT query from every server that has a CSV-file. To do this you have to connect to the other server and then import the module from the script server, so you can use it:

Import-Module -Name '\\SCRIPTSERVER\C$\Windows\system32\WindowsPowerShell\v1.0\Modules\Invoke-SQL'
Sign up to request clarification or add additional context in comments.

2 Comments

Next question is can the remote machine insert data directly into the sql database. I would like to know a good way to insert data from a remote machine into a sql database
Answer updated, you can import the module from any server once it's installed on your script server for example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.