Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using PsGet through a Proxy

Tags:

powershell

I'm having a hard time modifying PsGet to work though a proxy. I replaced every $client initialization on PsGet.psm1 with this

# $client = (new-object Net.WebClient)
$proxyAddr = (get-itemproperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings').ProxyServer
$proxy = new-object System.Net.WebProxy
$proxy.Address = $proxyAddr
$proxy.useDefaultCredentials = $true
$client = new-object system.net.WebClient
$client.proxy = $proxy

but I still keep getting the DotNetMethodException during the WebClient request.

like image 897
GaiusSensei Avatar asked Jan 18 '12 04:01

GaiusSensei


1 Answers

Give this a try. Use [System.Net.WebRequest]::DefaultWebProxy instead of the registry read.

$wc = New-Object System.Net.WebClient
$wc.Headers.Add("User-Agent","Mozilla/4.0+")        
$wc.Proxy = [System.Net.WebRequest]::DefaultWebProxy
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$wc.DownloadString("https://github.com/chaliy/psget/raw/master/PsGet/PsGet.psm1")
like image 52
Andy Arismendi Avatar answered Nov 01 '22 05:11

Andy Arismendi