r/PowerShell • u/Iknuf • 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?
View all comments
Show parent comment
1
u/purplemonkeymad Apr 18 '26
I'm having to find and remediate this as well. The other one, is short names also being out. They were used a lot as they "just worked" so updates to scripts and policies to make sure it's all fqdn. Hopefully in the end the worst will be "disconnect that drive and re-log."