We help IT Professionals succeed at work.

CMD file - Alert mail not sent from scheduled task.

173 Views
Last Modified: 2017-05-23
I have a CMD file that connects to an FTP server to transfer files. When the FTP server is unavailable, an alert email should be sent by a seperate Powershell script. Everything works fine when I run the script form a Command Prompt, when the CMD file is executed by a scheduled task the mail is not sent.

Since there is no problem when the batch file is executed from a command prompt, I guess the problem must be located in the scheduled task-settings, not in the script.

Batch file details:
<code to connect to the FTP server>
if %ERRORLEVEL% neq 0 goto error
 
echo Upload succeeded, moving local files
<code to move the files from the local drive to the FTP server>
exit /b 0
 
:error
powershell.exe -ExecutionPolicy Bypass -Command ".\mail.ps1"
exit /b 1

Open in new window


Scheduled task details:
- runs with administrator account
- run whether user is logged on or not
- run with highest priviliges
- Action: Start a program
- Program/script: C:\Windows\System32\cmd.exe
- Add arguments: /c <path to the cmd file>
 
Any ideas what the limitation of the scheduled task could be?
Comment
Watch Question

Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Lead SaaS Infrastructure Engineer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Shaun VermaakSenior Consultant
CERTIFIED EXPERT
Awarded 2017
Distinguished Expert 2019

Commented:
I would use blat https://sourceforge.net/projects/blat/ and natively call it from the batch file.
I would use Powershell to mail if whole thing was Powershell
Ben Personick (Previously QCubed)Lead SaaS Infrastructure Engineer
CERTIFIED EXPERT

Commented:
Hey Shawn,

  I used to use Blat, I switched over to using a Powershell script I wrote to send email as well.

  Personally, I don't like to have to install and maintain 3rd party executables myself, and the PowerShell is easy to use.

  But it's a matter of preference really.

Ben
Shaun VermaakSenior Consultant
CERTIFIED EXPERT
Awarded 2017
Distinguished Expert 2019

Commented:
My point is that I would do away with the bat file completely and use Powershell (one script) to do FTP, move file and Notification

Author

Commented:
The longterm solution will be a complete powershell script for transferring the data and generating alert messages. For the short term I'll try the suggestion that Ben Personick gave and post the result. Thanks!

Author

Commented:
Thanks guys, the suggestion from Ben works like a charm.
Ben Personick (Previously QCubed)Lead SaaS Infrastructure Engineer
CERTIFIED EXPERT

Commented:
Hey A Vader, glad to help :)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.