PowerShell下载文件

$webRequest = [System.Net.HttpWebRequest]::Create("http://go.microsoft.com/fwlink/?LinkID=149156")
$webRequest.Method = "GET";
$webRequest.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"

$response = $webRequest.GetResponse()
$stream = $response.GetResponseStream()

$reader = New-Object System.IO.BinaryReader($stream)
$bytes = New-Object System.Byte[] $response.ContentLength 

for ($read = 0; $read -ne $bytes.Length; $read += $reader.Read($bytes,$read,$bytes.Length - $read) ){ }
[System.IO.File]::WriteAllBytes("c:tempSilverLight.exe",$bytes);
原文地址:https://www.cnblogs.com/dreamer-fish/p/5583145.html