I have a .bat file that executes perfectly when run on its own. When used in Windows Task Scheduler it runs, but always downloads the wrong file (the same file each time). I know the scripting is good because we have other scheduled tasks that use the same script and work perfectly. The task is configured the same as all other tasks utilizing the same script, and it is using the same credentials as when I run the .bat file manually.
WinSCP is supposed to download a file based upon yesterday's date. When run manually it does it perfectly every time. When run from the task scheduler it always downloads the file dated '20180928'. I am including my .bat script here for review, but I truly believe the problem is elsewhere. Any ideas?
:: Create a variable containing yesterday's date
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%day%,now) : d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^& right(100+day(s),2)
for /f %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "result=%%a"
:: Create a variable to hold the password needed to unzip the LiveVox recordings
:: Create a variable for the output folder for zipped LiveVox calls to send to callminer
:: Create a folder with yesterday's date on Charlie
md \\charlie\Recordings\LiveVox\%date-yesterday% >nul 2>&1
:: Script the FTP download action to a txt file
echo option batch abort >> DownloadLiveVoxCalls.txt
echo option confirm off >> DownloadLiveVoxCalls.txt
echo open LiveVox-Recordings >> DownloadLiveVoxCalls.txt
echo get -preservetime -transfer=binary /%date-yesterday%_RECORDINGS* \\jerry\c$\LiveVoxDailyCalls\ >> DownloadLiveVoxCalls.txt
echo exit >> DownloadLiveVoxCalls.txt
:: Execute the download script file
"C:\Program Files\WinSCP\winscp.com" /script=DownloadLiveVoxCalls.txt
:: Copy 7z.exe file to LiveVoxDailyCalls folder
copy "C:\Program Files\7-Zip\7z.exe"
:: Unzip recording file using password
for %%I in ("*.zip") do (
7z x -p%yourZipPassword% -y -o"%%~dpI" "%%~fI"
:: Delete downloaded zip file
:: Copy csv file from Jerry LiveVoxDailyCalls to Charlie csv file
pushd "\\charlie\Recordings\LiveVox\csv files"
:: Copy contents of LiveVoxDailyCalls to Charlie
:: Zip the call files to send to callminer
7z a %output%\LiveVoxDailyCalls_%date-yesterday%.zip *.vox
:: Delete the 7zip executable from Charlie
del "\\charlie\Recordings\LiveVox\%date-yesterday%\7z.exe" /q
:: Delete the contents of the LiveVoxDailyCalls folder
del "C:\LiveVoxDailyCalls\*" /q
:: Delete the FTP download script file so a fresh one can be made
del "C:\Program Files\WinSCP\DownloadLiveVoxCalls.txt" /q