0
votes

I have a simple powershell job that copies a file from my computer to a network folder. I have verified that it is able to run when manually triggered, but not through task scheduler. When triggering the task from Scheduler the history indicated that it has run as I get both "Action Completed" and "Task Completed".

copy C:\test.txt "\\network\folder\destination\" /Z /Y

On the job itself:

Action:

-Program/Script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

-Arguments: -file "C:\Users\me\Desktop\move.ps1"

Its allowed to run on demand, running through a user with access to the network folder, with highest privileges. Any trouble shooting ideas are greatly appreciated.

1
Have you verified that the script works when run manually?Persistent13
Can the user login to run a batch job? technet.microsoft.com/en-us/library/cc957131.aspxShawn Esterman
Yes, forgot to mention that, was about to update the post.user8162541
You can use Windows PowerShell ISE, which will act as an IDE where you can have breakpoints as well to figure out where your script is debunking and/or any values you may want to check.Dylan Wright
Normally, in PowerShell, copy is aliased to Copy-Item, which does not use the same syntax as the CMD.EXE copy command. The switches /Z /Y suggest that you are thinking of the CMD.EXE copy command, not the Copy-Item PowerShell cmdlet.Jeff Zeitlin

1 Answers

0
votes

You're trying to call a cmd function from PowerShell which has copy aliased to the Copy-Item cmdlet by default. You'd need to modify your script to call cmd if you want to keep that line as it is.

& cmd /c copy C:\test.txt \\network\folder\destination /Z /Y