$url = "http://example.com" $output = "C:\path\to\destination\file.tar.gz" $request = [System.Net.HttpWebRequest]::Create($url) $request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64)" $response = $request.GetResponse() $requestStream = $response.GetResponseStream() $localStream = [System.IO.File]::Create($output) $buffer = New-Object Byte[] 1024 while (($bytesRead = $requestStream.Read($buffer, 0, $buffer.Length)) -gt 0) $localStream.Write($buffer, 0, $bytesRead) $localStream.Close() $requestStream.Close() $response.Close() Use code with caution. Method 4: BITS (Background Intelligent Transfer Service)
Files downloaded via WebClient are often marked as "from the internet," which can cause them to be blocked. You may need to use Unblock-File after downloading, or configure your script to handle this appropriately. powershell 2.0 download file