January 12, 2021 at 10:11 am
Hi,
I am running below code, running fine in PS terminal and ISE. When I am running it from SQL agent job it's failing with
"Message - Unable to start execution of step 1 (reason: line(1): Syntax error). The step failed."
---------------------------------------------------------------------
#Create folder
$f = New-Item "E:\Archive_backups\$(get-date -f yyyy-MM-dd-hh-mm-ss)" -ItemType Directory -Force
#Copy all files
Copy-Item E:\MainBackups\* $f.FullName
------------------------------------
Please suggest.
January 12, 2021 at 11:12 am
Does drive E: exist on the SQL Server machine, or is it a mapped drive?
January 12, 2021 at 1:12 pm
E drive is local drive not an network mapped.
January 12, 2021 at 5:03 pm
As stated in the other thread you posted to - the problem is that SQL Server Agent uses tokens, and tokens are defined by $(token). Since your code has this: $(get-date -f yyyy-MM-dd-hh-mm-ss), SQL Server Agent is attempting to parse that out as a token.
Change your code so it doesn't use that structure, something like:
$directoryName = "E:\Archive_Backups\" + (Get-Date -f yyyy-MM-dd-hh-mm-ss);
$f = New-Item $directoryName -ItemType Directory -Force;
With that said - you can simplify your code to just this:
Copy-Item -Path E:\MainBackups\ -Destination "E:\Archive_Backups\" + (Get-Date -f yyyy-MM-dd-hh-mm-ss);
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy