← script library

Download and Extract Files with BITS in PowerShell

System AdministrationAugust 17, 2026

A reusable download function built on BITS transfer that saves to a target folder and unpacks the archive when it is a zip. Written to be called several times in one run, which is how it is used here to pull down a set of policy definition and GPO template archives.

powershell
# File Downloader
#------------------------------------

function Download-File {
    param (
        [string]$Link = "",
        [string]$TargetFolder = "",
        [string]$Filename = "",
    )

    # Set output ZIP path
    $TargetFile = Join-Path $TargetFolder $Filename

    if ($Link) {
	    # Download
		Start-BitsTransfer -Source $Link -Destination $TargetFile -ErrorAction Stop

		Write-Host "Downloaded file to $TargetFile"
		Start-Sleep -Seconds 2

		if ($TargetFile -like '.zip') {
			# Extract and clean up, assuming it's a .zip file
    		if (Test-Path $TargetFile) {
        		Expand-Archive -Path $TargetFile -DestinationPath $TargetFolder -Force
        		Remove-Item -Path $TargetFile
        		Write-Host "Extracted archive to $Target and deleted zip"
    		}
		} else {
        	Show-Warning "File is not archive skip..."
    	}
    } else {
        Show-Warning "Could not find download link."
        return
	}
}

Download-File -Link "https://files.com/PolicyDefinitions.zip" -TargetFolder ".\" -Filename "PolicyDefinitions.zip"
Download-File -Link "https://files.com/GPO_Templates.zip" -TargetFolder ".\" -Filename "GPO_Templates.zip"

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.