Share via

PowerShell Script Will Not Work in Task Scheduler

Dustin Albright 41 Reputation points
2025-04-01T15:30:04.18+00:00

I have a PowerShell script that checks for a user's last password set date and if it more than 166 days ago it will send them an email reminding them to change their password. The script works well in PowerShell ISE as long as I run as administrator so it can correctly pull the AD property pwdLastSet.

When I try to automate this task using Task Scheduler, it does not work. It used to work about a year or so ago, but I'm not quite sure what has changed with all the Windows updates between now and then.

I have the task using a domain admin account, the 'Run whether user is logged on or not' option is checked, the 'Run with highest privileges' box is checked, and it is configured for Windows Serve 2016. The trigger is set to daily at 2am. In the Actions tab I have 'Start a program' selected, "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" for the 'Program/script' field, and "-File "C:\PasswordExpirationNotifcation.ps1"" in the 'Add arguments (optional)' field.

Every time I manually run the task it ends with (0x1) as the Last Run Result. I tried moving the script to a share on our file server that has open access to all domain users and received the same result.

Any ideas on what I could do different?

Windows for business | Windows Server | User experience | PowerShell

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.