Download Files Inside a Deployment

camera pics feb 2010 048
Jason Amick|July 9, 2020
download files inside a deployment
download files inside a deployment

So you want to use a freshly downloaded file inside your deployment, but you want this deployment to remain a Set It and Forget It package. You can do this with any file for which you can get a download link. This is also useful if you need to ensure your installer is installing the most up to date templates or modules when they are separate downloads. We will cover how to do this, and how to make sure you can use that file during your deployment.

Destination Caveat

When downloading a file from inside a deployment, you will need to keep in mind that the section for the working directory will be inside of a runner service that will get obliterated when that step completes. If you do not use the file and finish with it in the same step, that file will get destroyed as well. So using the working directory for your destination may not always be the best practice. You can utilize temp folders instead or any other location if you need to use that file in later steps, you can clean it up at the end.

With CMD Prompt

Let us start with a method in CMD prompt. For this method, we will use curl.exe. We will not go into all the switches because the list is enormous, but you can view these by running curl.exe –help. The syntax for this example will be curl.exe “sourceWebAddress” -o “Destination” the switch we are using is -o meaning output or Write to file.

curl.exe https://ftp.nluug.nl/pub/graphics/blender/release/Blender2.83/blender-2.83.1-windows64.msi -o blender-2.83.1-windows64.msi msiexec.exe /i "blender-2.83.1-windows64.msi" ALLUSERS=1 /qn /norestart /log output.log
cmd step

This command will reach out to the given url, grab that file, and save it to the location we entered as the destination. In this case, we are going to use the working directory because we are going to kick off the silent install in the same step.

In PowerShell, we can use Invoke-WebRequest or Invoke-RestMethod. The difference is the latter can natively understand a REST API return. So that is what we will use for this example.

$Uri = https://ftp.nluug.nl/pub/graphics/blender/release/Blender2.83/blender-2.83.1-windows64.msi Invoke-RestMethod -Uri $Uri -OutFile blender.msi msiexec.exe /i "blender-2.83.1-windows64.msi" ALLUSERS=1 /qn /norestart /log output.log
2ndPSstep

Easy, Right?

So now that we have learned to download a file and use it in either a CMD step or a PowerShell Step, the world is a better place. Keep in mind that the file will not be found to add in an Install step because it does not exist while creating the package. It also cannot be referenced in later steps unless you use a CMD or PowerShell step to call it from wherever you decided to stash the little fella.


camera pics feb 2010 048
Jason Amick

After a decade of grinding away what seems like a lifetime in IT\sysadmin work, the only thing Jason loves more than work is sleeping, eating, drinking, riding his Harley, spending time with his kids, pretty much most things. This is why Jason automates so many tasks, if it can be automated it should be automated. If it can't, then why do it?

Related Articles