您的位置:首页 > 运维架构 > Shell

Getting through a proxy server with PowerShell

2010-03-17 20:43 483 查看
在使用powershell中经常需要使用到一些网上的资源,那么如何通过代理来访问网上的各种资源呢?
下面就是一种实现方式,具体的代码及说明如下:
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Net")

# 创建代理$proxy = new-object System.Net.WebProxy "isa.pumch.local:8080"

# 设置访问代理的凭据
$cred = get-credential
$proxy.credentials = $cred.GetNetworkCredential()

#下载一个页面
$WebClient = new-object System.Net.WebClient
$WebClient.proxy = $proxy
$url = "http://www.streamline-it-solutions.co.uk/blog/post/Getting-through-a-proxy-server-with-PowerShell.aspx"
$content = $WebClient.DownloadString($url)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息