PowerShell - Transfer Files Using BITS protocol as a scheduled task - not working when logged off

1

I have written a PowerShell script which uses the BITS transfer protocol in order to transfer large files from Source machine to destination machine. When I run the PowerShell script manually logging into my destination remote machine (where the files need to be copied) then the files are getting copied without any issues.

But When I have created a scheduled task that runs the PowerShell script daily at a particular time. It is throwing the following error

The operation being requested was not performed because the user has not logged on to the network. The specified service does not exist. (Exception from HRESULT: 0x800704DD)

The script is getting worked only when I log-in to my destination machine where the file is being copied. If at all I log off from that machine at that scheduled task time then I am getting the error. Please suggest what needs to be done in order to make the scheduled task run even if I log off from that machine.

powershell
scheduled-tasks
bit
asked on Stack Overflow Jan 12, 2018 by Kamal • edited Nov 10, 2019 by halfer

1 Answer

2

According to the documentation about BITS found on https://msdn.microsoft.com/en-us/library/windows/desktop/aa362708(v=vs.85).aspx (and the specific Powershell documentation found on https://msdn.microsoft.com/en-us/library/windows/desktop/ee663885(v=vs.85).aspx) the user that created the jobs has to be logged on.

Powershell Doc : Important   When you use *-BitsTransfer cmdlets from within a process that runs in a noninteractive context, such as a Windows service, you may not be able to add files to BITS jobs, which can result in a suspended state. For the job to proceed, the identity that was used to create a transfer job must be logged on. For example, when creating a BITS job in a PowerShell script that was executed as a Task Scheduler job, the BITS transfer will never complete unless the Task Scheduler's task setting "Run only when user is logged on" is enabled

Generic documentation : BITS continues to transfer files after an application exits if the user who initiated the transfer remains logged on and a network connection is maintained. BITS will not force a connection. BITS suspends the transfer if a connection is lost or if the user logs off. BITS persists transfer information while the user is logged off, across network disconnects, and during computer restarts.

In short : what you want is not possible.

(this is one of the reasons why you should always read the documentation when encountering problems like these)

answered on Stack Overflow Jan 12, 2018 by bluuf

User contributions licensed under CC BY-SA 3.0