Powershell can't connect to internet at all

I have searched all over the place for an answer to this question, but I think I may be missing Google ninja skills.

I'm trying to run a simple command in Powershell that downloads a string (actually, I want to download msi and run it, but I've narrowed the problem down to a simple example). script I am running:

$client = New-Object System.Net.WebClient
$client.DownloadString("http://google.com") | Out-File google.html

      

The error I am getting:

Exception calling "DownloadString" with "1" argument(s): "Unable to connect to the remote server"
At line:1 char:1
+ $client.DownloadString("http://google.com") | Out-File google.html
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WebException

      

PSVersion = 4.0

I ran this script on a colleague's computer ( PSVersion = 3.0 ) and it works great. So I know the code works. I also recreated this code in a C # console application that looks like this:

static void Main(string[] args)
{
    using(var client = new System.Net.WebClient())
    {
        var content = client.DownloadString("http://google.com");
        File.WriteAllText("D:\\google.html", content);
    }
}

      

And it works on my machine - so I know this is not a .NET Framework issue. And strangely, I can call this one exe

from Powershell and it works.

I've narrowed it down to a Powershell problem, but I can't for the life of me figure out what. I obviously did something with my machine to break the Powershell connection to the internet, but can do something with someone who knows more than me about what's going on behind the scenes.

Pay attention . It has nothing to do with PS Remoting. I don't think so, but I am not trying to use PS Remoting. I do not think...

+3


source to share


1 answer


Are you using PowerShell as a different account (e.g. administrator)? Perhaps your account settings are different from your regular account? Maybe try setting $ client.Proxy = $ null before uploading and see if it helps.



+4


source







All Articles