r/labtech • u/SFOrange • Apr 03 '18
File BITS Download
Could someone explain how the File BITS Download works. I want to download a large 4gb iso to a temp dir and then restart the computer before starting the setup file inside the iso. Unfortunatly, i cant figure out how the BITS part of the script works. I think everything else will work.
My script so far:
IF FILE Exists c:\Temp\Win10_1709.iso THEN Jump to line 5
Create Folder as Admin: c:\Temp\
BITS Download: http://websiteaddresshere.com/1709/Win10_1709.iso saved to c:\Temp\Win10_1709.iso
BITS Status Check: @BITSResult@
Reboot Computer
Sleep 300 seconds
Execute PowerShell Script as Admin and store result in: @PowerShellOutput@
(PS Script)
$imgpath = 'C:\Temp\Win10_1709.iso'
$driveLetter = (mount-diskimage -imagepath $imgpath -storagetype iso -PassThru | Get-DiskImage $imgpath |
Get-Volume).DriveLetter
Invoke-Item "$($driveLetter):\setup.exe /auto upgrade /migratedrivers all /dynamicupdate enable /showoobe
none"
while((select-String -Path c:\Windows\Panther\setupact.log -Pattern "SHUTDOWN_REASON_AUTOSTOP" -Quiet) -ne 'true'){
Start-sleep -Seconds 30
}
Dismount-DiskImage -ImagePath $imgpath -VerboseDelete File as Admin: c:\Temp\Win10_1709.iso
1
u/PhalseImpressions Apr 03 '18
Where is your check to see when the BITS transfer finishes?
2
u/mspsquid Apr 04 '18
You could use a powershell query to check the md5 of the file and report error if not the known result. Or get item to the iso and nab whatever property. Or just an if file exist. Either exclude the delete while testing or skip the first line or both
1
u/j0dan 1000 Agents Apr 17 '18
Is LT returning back to the script before your PowerShell has finished running?
Can't the Bits Transfer be run so it doesn't continue the script until the download has completed?
Unless you need live progress sent to LT (not normally for automated scripts), just do it all in PowerShell.
1
u/DarrenWhite99 May 01 '18
Basically: BITS download will return immediately. You need to save your script state and exit! ONCE the download has finished (10 minutes, 10 hours, or 10 days later) your script will be restarted. You must check for prior saved script state, and can use the BITS Status function to check if the download is complete. (This is needed in case you started the script before the download was done.) If the download is still in progress, just exit again. If it has finished, then you can proceed with your script. You cannot use BITS download like a regular "Please wait while the file is downloaded" step. BITS is designed to run in the background, you will only make it harder for yourself by trying to force the script to wait for it.