Share via

Problem getting a powershell script to run in Task Scheduler

Kaplan, Andrew H 226 Reputation points
2023-08-09T18:03:28.6366667+00:00

Hello.

I am trying to get a PowerShell script to run once every half hour in the Task Scheduler utility. The platform is Windows Server 2019 Standard Edition. I configured the script to run on a schedule starting at 12:00 AM every day, and repeat every 30 minutes indefinitely.

The script is designed to do a check of disk space usage on several remote servers, and email the results as an attached html file. The user account that is associated with the script does have Administrator access on all servers. The script itself is configured to run whether the user account is logged in or not, and also with the highest privileges.

I have confirmed the script will run by interactively running it in Powershell, and also when I click on 'Run' within the Task Scheduler. According to the Last Run Result, the script ran successfully, but the email with the attached html file is not being sent to the intended recipient.

Windows for business | Windows Server | User experience | Other
0 comments No comments

1 answer

Sort by: Most helpful
  1. Vahid Ghafarpour 23,605 Reputation points
    2023-08-09T18:45:48.1266667+00:00

    The environment in which a script runs when triggered by Task Scheduler might differ from when it's run interactively. Ensure that the script does not depend on any specific user settings or environment variables that might be different when running under Task Scheduler.

    Was this answer helpful?

    0 comments No comments

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.