question

meachcarnahan avatar image
meachcarnahan asked

Syntax Error While Running Powershell Command Through SQL Agent

Hey Everyone,

I know this will be something simple but hey it's Friday and i can't see the syntax error. Looking for a second set of eyes to help me out here.

I have a SQL Agent job that runs a simple copy command for a bunch of csv file in a folder to another folder every hour. This is the powershell command I need assistance on as it runs fine in powershell but not through the agent

$source_dir='E:\excel_files\MasterFiles'

$dest_dir='E:\excel_files\Upload'



Get-ChildItem -Path $source_dir\ | ForEach-Object {

Copy-Item -Path $_.FullName -Destination "$dest_dir\$($_.BaseName + '_' + (Get-Date).ToString("MMddyyyy_HHmmss") + $_.Extension)"

}


Thanks in advanced!

sql-agentpowershell
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

What error message are you getting?

0 Likes 0 ·
meachcarnahan avatar image meachcarnahan ThomasRushton ♦♦ ·

Hi Thomas,


The error is this:

Message

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

0 Likes 0 ·

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.