Question

I have a powershell script where I perform a upload then I must do a RESTful request about the file I just uploaded. Right now it works great as a non-asynchronous method

Start-BitsTransfer -Source $fullPath -Destination "https://www.example.com/bitsupload/$Guid.$SourceFile" -Credential $Credential -TransferType Upload

$web = New-Object Net.WebClient
$web.DownloadString("https://www.example.com/newbitspost/?filename=$Guid.$SourceFile&filedescription=$Description&Friendlyname=$SourceFile")

However I would like to run this in the background so the end user can close the window (more importantly, and my final goal, logoff) and it will still be transferring.

I know I can add -Asynchronous to my Start-BitsTransfer but I can not figure out how to get that GET request performed after the transfer completes.


Thanks to the false positive Duplicate question link (The other question's answer never actually solves the problem it just shows how to manually execute something afterwards) My question boils down to: How do I duplicate the functionality of /SetNotifyCmdLine from the deprecated BitsAdmin program.

Was it helpful?

Solution

The answer is: You can't.

At least not using the BITS cmdlets / BitsTransfer module in PowerShell v2. Your only choice would be to use deprecated functionality, or roll a custom solution interfacing with the BITS API. There is a project called SharpBITS.NET that might be helpful.

Some more details on what you are hoping to accomplish might help others provide alternatives as well. I am also curious as to what alternatives you have considered - like can you do your RESTful GET before uploading the file? or even as part of the upload perhaps - embed parameters in the query string? I would also consider what it means to do the upload in the background without the user being logged in - or another user logged in, or what happens if they shutdown the computer (or otherwise interrupt the transfer). It might make more sense to have a login script check the status of the BITS transfer jobs and take action at that time for example. For the case where they don't logoff, you can also hide the window and periodically poll the BITS jobs to check for completion.

I know these aren't ideal - and maybe not even worth receiving the accepted answer. I do hope they help though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top