How to fix "iwr/irm : Unable to connect to the remote server error" in Powershell 5.1

aashish kumar 26 Reputation points
2022-12-05T23:01:05.023+00:00

Hello I am trying to install Scoop in my Windows 10 machine via following commands

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser # Optional: Needed to run a remote script the first time

irm get.scoop.sh | iex

I had already installed scoop ones, but I uninstalled it recently and now when, I am trying to install it again
it gives me following error:

irm : Unable to connect to the remote server

At line:1 char:2

  • irm get.scoop.sh | iex
  • ~~~~~~~~~~~~~~~~
  • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExcetion
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

i also tried installing spicetify andi got the similar error.

iwr -useb https://raw.githubusercontent.com/spicetify/spicetify-cli/master/install_curl.ps1 | iex

error:

iwr : Unable to connect to the remote server
At line:1 char:1

  • iwr -useb https://raw.githubusercontent.com/spicetify/spicetify-cli/m ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
  • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

For the information:

1)i recently got a new Fiber connection in my home and before that it used to work.
Just to let you know if there is any proxy error or something (c=got a hint about it from web).

Thanks you in advance.

Windows for business | Windows Client for IT Pros | Networking | Network connectivity and file sharing
Windows for business | Windows Server | User experience | PowerShell
Windows for business | Windows Client for IT Pros | User experience | Other
{count} vote

Accepted answer
  1. MotoX80 36,401 Reputation points
    2022-12-11T16:58:46.703+00:00

    Go find a friend and see if their PC resolves raw.githubusercontent.com to that IP address.

    Did you do that? Have someone on another PC in India do an "nslookup raw.githubusercontent.com". What IP do they see? Do they use the same ISP that you do?

    As for these addresses i have tried out in powershell 7.1 and 5.1

    This has nothing to do with any version of powershell. It is a networking issue.

    As for the Problem with ISP can you be more detailed on this part as i am quite new in this field.

    The question is: why does raw.githubusercontent.com resolve to 49.44.79.236 on your pc?

    I used Nmap to analyze that IP and it found 2 open ports, 554 and 7070. HTTP and HTTPS are NOT open. That is not a web server. Nmap reports that it is probably a cable modem.

    269375-image.png

    My laptop is configured to use DHCP from my WIFI router. It serves as the DNS server to resolve local names on my network. Run "ipconfig /all" to see your pc's DNS servers. What are they?

    To resolve internet based names, my router uses 2 Verizon (my ISP) DNS servers. I can see that in my routers configuration.

    Paste these commands into a command prompt window. It will query the currently configured DNS servers and also the Google DNS servers.

    nslookup.exe get.scoop.sh  
    nslookup.exe get.scoop.sh 8.8.8.8  
    nslookup.exe raw.githubusercontent.com   
    nslookup.exe raw.githubusercontent.com 8.8.8.8  
    

    If your pc uses your router for DNS you should see that in the "server".

    269329-image.png

    In that case you would need to logon to your router and see what DNS servers it is configured for. Here is what mine looks like.

    269330-image.png

    What address is your router using?

    My Verizon DNS server resolves the names correctly.

    269411-image.png

    One option you have is to set your NIC or your router to use Google's 8.8.8.8 DNS server.

    You would first want to try to understand what DNS servers you are using and why the names resolve as they do.


18 additional answers

Sort by: Most helpful
  1. MotoX80 36,401 Reputation points
    2022-12-06T13:54:54.507+00:00

    i recently got a new Fiber connection in my home and before that it used to work.

    Well then this sounds like some networking issue and not a Powershell problem.

    Are you posting to this site from the pc that has the problem? Can your browser access those web sites that you listed? Can Invoke-WebRequest access other sites like Google, Bing, Microsoft.com?

    What DNS servers are you using? Did that software that you installed add any entries to your hosts file? Check the contentts of C:\Windows\System32\drivers\etc\hosts.

    You mentioned proxy, is one set?

    NetSH WinHTTP Show Proxy    
    

    Have you tried temporarily turning your firewall off?

    0 comments No comments

  2. aashish kumar 26 Reputation points
    2022-12-06T17:13:36.693+00:00

    @MotoX80

    yes, I am posting from the pc that has problem, I can access everything on internet, even the Invoke-WebRequest works if i try to download firefox or something else.

    Hey, I did not install any software, i just got a fiber connection and started using ethernet and nothing else. if this helps

    I am posting the content of C:\Windows\System32\drivers\etc\hosts. as I don't fine anything peculiar in that:

    Copyright (c) 1993-2009 Microsoft Corp.

    This is a sample HOSTS file used by Microsoft TCP/IP for Windows.

    This file contains the mappings of IP addresses to host names. Each

    entry should be kept on an individual line. The IP address should

    be placed in the first column followed by the corresponding host name.

    The IP address and the host name should be separated by at least one

    space.

    Additionally, comments (such as these) may be inserted on individual

    lines or following the machine name denoted by a '#' symbol.

    For example:

    102.54.94.97 rhino.acme.com # source server

    38.25.63.10 x.acme.com # x client host

    localhost name resolution is handled within DNS itself.

    127.0.0.1 localhost

    ::1 localhost

    127.0.0.1 platform.wondershare.com

    I tried turning off the firewall, but it didn't work for me.

    0 comments No comments

  3. aashish kumar 26 Reputation points
    2022-12-06T17:15:30.39+00:00

    @MotoX80

    and for the result of NetSH WinHTTP Show Proxy

    it gave following result:

    Current WinHTTP proxy settings:

    Direct access (no proxy server).  
    
    0 comments No comments

  4. MotoX80 36,401 Reputation points
    2022-12-06T20:02:54.767+00:00

    Do you get a 400 response if you try to connect to a partial url?

    PS C:\> iwr  https://raw.githubusercontent.com/spicetify  
    iwr : 400: Invalid request  
    At line:1 char:1  
    + iwr  https://raw.githubusercontent.com/spicetify  
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
        + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc  
       eption  
        + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand  
    

    That would indicate that you can traverse the internet and connect to the remote server.

    What are you using for antivirus software? Any changes there? Both of your examples are referencing and trying to execute scripts. Have you tried just the iwr without the iex? Or may try the -OutFile switch and see if can download a file.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.