0

Need more help from you brilliant folks.

I am trying to import a CSV file to a SQL table with this code:

$SQLServer = "MYSQLINSTANCE"
$SQLDatabase = "DBATools"
$SQLString = "Server=$SQLServer;Database=$SQLDatabase;Integrated Security=True;"
$SQLTable = "dbo.MyTable"
$CSVFile = "\\remotesrvr\OutputShare\Output.csv"
$Header = 'RecordedDTM','TablespaceName','PhysicalFileName','MaxSize','UsedSize','FreeSize','PctUsed'
Import-CSV -Path $CSVFile -Header $Header | Select-Object -Skip 1 | ForEach-Object {Invoke-SqlCmd -ConnectionString $SQLString -Query "INSERT INTO $SQLTable VALUES ('SVPPDRMDB01','$($_.RecordedDTM)','$($_.TablespaceName)','$($_.PhysicalFileName)',$($_.MaxSize),$($_.UsedSize),$($_.FreeSize),$($_.PctUsed))"}

It runs successfully in a Powershell prompt, but when I create a SQL job of type Powershell, I get the following error:

Unable to start execution of step 1 (reason: line(7): Syntax error).  The step failed

Not a lot of help, huh. What am i missing?

Darrell
  • 125
  • 3
  • 10

0 Answers0