I am having a strange issue with task scheduler on my Win 7 machine not properly running a Powershell script which is supposed to email me a PDF file daily.
If I run the script manually via ISE...I get the PDF file as an attachment just fine. However if I run it via task scheduler (even right clicking and running instead of scheduling) it runs the script but the email I receive is just garbled text.
Here's how task scheduler is configured,
Actions: Start a program: :\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Add arguments : -NonInteractive -Command "& 'c:\temp\DailyReport.PS1' "
On General tab I selected run with highest privileges. Its running under my domain user account which is also local admin and has log on as batch privileges.
The script itself is simple...just check for the presence of a PDF file, attach it and send the email. And it works when executed independently of task scheduler. So to me it's obvious that the problem is when I run it via task scheduler. What am I missing?
Copyright Notice:Content Author:「JoeKim」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/28585263/powershell-and-task-scheduler