Powershell – Scheduled PS Script Not Running

exchange-2013powershellscheduled-taskwindows-server-2012-r2

I'm trying to run the script from https://gallery.technet.microsoft.com/Password-Expiry-Email-177c3e27
I've corrected the variables for my environment and I'm able to run it from my workstation and the server just fine when running it manually but when I try to schedule it with Task Scheduler the task seems to run fine but nothing is sent out.

I've check my event logs and do not see errors popping up and the task history says the instance comes back with return code 0.

I've checked these two questions and other from Googling but adding extra arguments other than -file C:\path\script.ps1 seems to give long numbered return codes or just keeps running.

I'm running the task as administrator, running whether the user is logged on or not, running with highest privileges, and trying to have it run every night at midnight.

Is there anything else I'm missing?

Best Answer

It sounds to me like the user assigned to run this task has not been given the right to Logon as Batch.

This is a user right that is not automatically assigned to any user, even Administrators.

If you are on a member server you can set it in local policy. Fire up SecPol.msc and locate User Rights Assignment, make sure the user running the task is represented in the logon as batch group.

If you are doing this on a DC then Default Domain Policy usually defines this, edit via the usual GPO managmeent tools and again make sure your running user is represented in the logon as batch there.