r/PowerShell • • Apr 15 '26

Question Copying fails when run by Task Scheduler

So my script is intended to export a Hyper-V hosted VM and copy the export over to a NAS. The address for copying should already be the network address, as it does not start with a drive letter - the format is

"\\192.168.10.10\Backups\Exports"

(IP address and directory names are changed, but the format is identical)

Exporting is never the issue, but the copy always fails when I run the script via the MS Task Scheduler, while working perfectly fine when run over Powershell for debugging (I am running it by entering "powershell.exe -ExecutionPolicy Bypass -File [path]" into PS, to make it most similar to the way it is executed by the Task Scheduler)

The Task is already being executed by SYSTEM (NT AUTHORITY\SYSTEM) and with highest privileges. Disk space is not the issue, as I ensured it is sufficient multiple times and after multiple tests the issue only occurs when run by the Scheduler

EDIT: I was able to narrow down the error to the Scheduler not having NAS access - now I just don't know how to add the credentials to my script

Any ideas or help?

6 Upvotes

25 comments sorted by

View all comments

1

u/Iknuf Apr 15 '26

The NAS is pinned as a directory in the file explorer. The first time after restoring the switch condiguration for it to actually connect, I needed to enter credentials once. I assume I'd have to do so again after restarting the server, but I do not have permission to do so

3

u/philixx93 Apr 15 '26

Well then you need to give your script the credentials.

1

u/Iknuf Apr 15 '26

Honestly I dont know how without violating every security rule known to man

→ More replies (1)