Powershell and task scheduler
NickName:JoeKim Ask DateTime:2015-02-18T21:49:56

Powershell and task scheduler

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

More about “Powershell and task scheduler” related questions

Powershell and task scheduler

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......

Show Detail

Task Scheduler - Powershell elevated task

I have a script which works when it is manually executed the script works under these conditions: 1) I start start.ps1 which then elevates with admin user then executes main.ps1 script 2) the sta...

Show Detail

PowerShell / task scheduler / task exist check

Before deleting a task in the task scheduler with schtasks command, how can I check that a target task already exists or not with PowerShell? My question is deferent of yours, and sodawillow solve...

Show Detail

Powershell script works in Powershell but fails in Task Scheduler

I have a PowerShell script that sends an email via SMTP. The script runs fine inside Powershell ISE, but fails in Task Scheduler. I am on Windows Server 2012. I have other Powershell scripts tha...

Show Detail

Powershell file download and Task Scheduler

I am a beginner. I tried to schedule a download with local Windows 10's powershell. Tested in powershell, the script work and successful download the files. $client = (new-object System.Net.WebCli...

Show Detail

PowerShell Script not running when set in the task scheduler

I'm attempting to create a task via powershell to delete some files older then 6 hours, if I execute the script from powershell there are no issues, if I try to execute from task scheduler nothing

Show Detail

powershell script work with Task Scheduler

I have a powershell script that generates a report and exports it out as an excel file and then emails it as an attachment. This works perfectly when I run the powershell script, I then created a ...

Show Detail

How to call a task in Task Scheduler from a Powershell script?

I have seen various articles on how to schedule a Powershell script, but I have not see much of the reverse. I need to call a manual task in Task Scheduler from my PowerShell script. I am using

Show Detail

Import task scheduler xml file using cmd or powershell

I have exported task scheduler task in xml format and now i want to import it into different pc using cmd or powershell or any script only. How can i import task scheduler xml file into task schedu...

Show Detail

PowerShell script running as different user in Windows Task Scheduler

I am trying to configure a PowerShell script which will run in Windows Task Scheduler for multiple service accounts. I found a way to run the PowerShell script with a given user via the 2nd answer...

Show Detail