Trouble with PowerShell Scheduled Task on Windows Server 2025

0
2
Asked By CuriousTurtle42 On

I'm having some issues with a PowerShell script that's supposed to copy database dumps to another machine using robocopy. When I run the script manually, it works perfectly—copying all .bak files that are at least a day old and logging the robocopy results. However, when I schedule this task in Task Scheduler, it starts up but doesn't seem to do anything and ends with a success code (0x0). Here are the settings I'm using:

- **General Settings**: Running under my admin account with options to run whether the user is logged on or not, and to run with the highest privileges.
- **Triggers**: Set to run daily at 2 AM and is enabled.
- **Actions**:
- Program: `C:WindowsSystem32WindowsPowerShellv1.0powershell.exe`
- Arguments: `-ExecutionPolicy Bypass -File "C:MC_Scriptsoffsite.ps1"`
- Start in: `C:MC_Scripts`
- **Conditions**: Set to wake the computer if needed.

I've even tried using different accounts including local and domain admins, but the issue persists. Any suggestions?

3 Answers

Answered By ScripterDude On

If the script runs fine manually, it might be a context issue. Have you checked if it runs correctly under the SYSTEM account? That could help isolate permissions problems.

CuriousTurtle42 -

I’ve run it as SYSTEM and still faced the same issue. No luck.

Answered By AdminMaster On

Double-check that the account you're using has "Log on as a batch job" rights in the local security policy. Also, make sure to uncheck "Do not store password" in the task properties; it needs the password for network access, especially when moving files across machines.

CuriousTurtle42 -

The security policy has my account under Administrators, but I tried adding my account anyway. Still get the same result.

Answered By CodeNinja88 On

To get more insights into what's happening when the script runs as a scheduled task, you could add `Start-Transcript` to your script to enable logging, and make sure to use `-Verbose` with your cmdlets. This would document what the script is doing in real time. It's important to check the logs generated, even though you mentioned they are showing nothing when you run it manually.

PowerShellGamer01 -

I tried adding the transcript but it’s not logging anything when executed either way. The script runs fine manually, just not in the scheduled task.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.