0

When I run the task scheduler it gives me a (0x1) error code. Basically this is to copy all files on the desktop and place them in Google Drive.

Backup1.ps1

$action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument 'C:\Users\User\Desktop\Backup2.ps1'
$trigger = New-ScheduledTaskTrigger -Daily -At 9am
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "BackUP Google Drive" -Description "Google Drive Backup"

Backup2.ps1

Copy-Item "C:\Users\User\Desktop\*" -Destination "G:\My Drive\BackUp" -Recurse -Force

The Backup2.ps1 works 100% of the time when running it under PowerShell alone. The problem is that the task scheduler isn't completing the task due to the (0x1) error.

Tyrandis
  • 1
  • 1
  • 3
  • `0x1` isn't an error code, it's an exit code indicating that in one way or another, it could not do what it's expected to. If you select your task in the Task Scheduler then click the "History" tab and double click the event, it will likely give you a more helpful message. The only thing I can think of based on what's been provided is that the path to the script might have a space in it, and since you're not putting the path in quotes, it would treat the path as two separate positional parameters. – Jesse Nov 15 '22 at 18:35
  • 1
    Maybe G: isn't mapped. You should be able to do `backup.ps1 > logfile` I'm assuming the executionpolicy is remotesigned at least. – js2010 Nov 15 '22 at 18:37
  • This worked out after looking at this post https://stackoverflow.com/questions/18370547/windows-scheduled-task-succeeds-but-returns-result-0x1 This is something that Microsoft should fix. – Tyrandis Nov 16 '22 at 15:50
  • How did you fix it? – js2010 Nov 16 '22 at 16:17
  • In the post Andreas said "I have seen this problem multiple times while scheduling Powershell scripts with parameters on multiple Windows servers. The solution has always been to use the -File parameter: Under "Actions" --> "Program / Script" Type: "Powershell" Under "Add arguments", instead of just typeing "C:/script/test.ps1" use -File "C:/script/test.ps1" Happy scheduling!" – Tyrandis Nov 16 '22 at 17:47
  • My previous settings were "program/script" Powershell.exe "Add arguments" C:/script/test.ps1 – Tyrandis Nov 16 '22 at 17:50

0 Answers0