I'd like to write some code that uses BITS for copying very large files between disks on the same server (the second disk being a SAN level clone\snapshot).
I looked into BITS as i thought it would be a good way to get progress\percentage complete data on the transfers, as well as resume functionality etc
I have a lot of hosted Powershell and I thought i'd have a stab at using the inbuilt BITS cmdlets, as this would be a super quick way of doing it, i could write wrappers to get the stuff i need etc Unfortunately i ran into this:
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."
Doing anything through an impersonated Powershell runspace throws up 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)"
My web service is running as AppPoolIdentity, I impersonate when needed to do stuff. It makes sense this doesn't work via hosted Powershell, but can anyone think of a workaround? If this isn't possible, do i have any alternatives?
I was thinking of using BITS Compact Server as an alternative, but the documentation is ancient.
Have you thought of using robocopy? Running with the /ZB switch has always worked well for me, and you can improve performance with /J which enables unbuffered I/O. For output, run with /ETA and /TEE as well.