title: Bulk Insert from a CSV file to a table in a remote server
body: <p>I use SQL server 2012 and windows powershell. I try to do bulk insert from a local CSV file to  a table in a remote server. I tried to combine bulk insert with powershell script by using sqlcmd to connect to that server to execute the sql statement. I come up with </p>
  
  <pre><code>$path= "C:\UT\testdata.csv"
  $customerSizeQuery = "BULK INSERT dbo.test FROM '$path' WITH (FIELDTERMINATOR =',',     ROWTERMINATOR ='\n');"
  # $server and $database is fit as the exact server and database name in my real script
  SQLCMD -W -S $server -d $database -h-1 -Q ("$customerSizeQuery") 
  </code></pre>
  
  <p>obviously it does not work since path is my local path.</p>
  
  <p>I then tried to put the file content to a variable but it still have error. It seems to say $var is not a table</p>
  
  <pre><code>$path= "C:\UT\testdata.csv"
  $var= get-content $path
  $customerSizeQuery = "BULK INSERT dbo.test FROM $var WITH (FIELDTERMINATOR =',',     ROWTERMINATOR ='\n');"
  # $server and $database is fit as the exact server and database name in my real script
  SQLCMD -W -S $server -d $database -h-1 -Q ("$customerSizeQuery")
  </code></pre>
  
  <p>I am a beginner in sql and powershell and does not have an idea how to do it.</p>
  
  <p>Is there any body having any suggestions?</p>
  
  <p>Thanks so much!</p>