码迷,mamicode.com
首页 > 系统相关 > 详细

PowerShell下载文件

时间:2016-06-14 12:01:50      阅读:402      评论:0      收藏:0      [点我收藏+]

标签:

$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);

PowerShell下载文件

标签:

原文地址:http://www.cnblogs.com/dreamer-fish/p/5583145.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!