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 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,458 questions
Windows 10 Network
Windows 10 Network
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Network: A group of devices that communicate either wirelessly or via a physical connection.
2,340 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,504 questions
{count} vote

Accepted answer
  1. MotoX80 33,296 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. aashish kumar 26 Reputation points
    2022-12-06T23:36:32.887+00:00

    @MotoX80

    when i try to connect to partial url like
    PS C:\> iwr https://raw.githubusercontent.com/spicetify

    i get the same error but giving it a proper address like

    https://github.com/spicetify/spicetify-cli/blob/master/install.ps1 -Outfile 'install.ps1'
    it Downloads the file but when i try

    ./install.ps1 - ? then it is not able to run the script and gives error

    I Haven't used any antivirus Except windows Defender
    i thing i am getting this problem only in connecting with github and it might be related to some proxies as mentioned in scoop.sh website
    267908-web-capture-7-12-2022-5023-githubcom.jpeg

    I tried the second option but was not able to get through it because i literally don't any ideas about Port and Ip address

    I also tried it with spicetify and it was the same issue.
    "it says ampersand not allowed" please the below image:

    267963-screenshot-2022-12-07-051521.png
    while i tried to search online i found this website

    How to use git through proxy

    0 comments No comments

  2. MotoX80 33,296 Reputation points
    2022-12-07T01:24:13.413+00:00

    You are assuming that iwr is returning a script that you can execute, but it's probably returning HTML output. That's what is generating those errors. Open install.ps1 with notepad and you will see what I mean. I expect it to be HTML and not Powershell

    If you are on a home network, just ignore any thought of a proxy. You should only need that on a corporate network where you network administrator would tell you the IP and port to use.

    Try something like this..

    iwr https://github.com/spicetify/spicetify-cli/blob/master/install.ps1 -Outfile 'c:\temp\test.htm'  
    

    Then open test.htm with a browser and see what's in it.

    0 comments No comments

  3. aashish kumar 26 Reputation points
    2022-12-07T13:52:04.643+00:00

    @MotoX80

    Hey sorry for the late Response, just as you mentioned iwr is returning an Html file not ps1 script so that's why it was showing the errors.
    BTW, I am at my home and as you said there should be no issue of Proxies then I don't get what's causing the issue, I even tried Turning off the Firewall and Resetting the Network Settings in Windows.

    And the output of: iwr https://github.com/spicetify/spicetify-cli/blob/master/install.ps1 -Outfile 'c:\temp\test.htm'

    was giving an error:

    • iwr : Could not find a part of the path 'C:\Downloads\test.htm'.
      At line:1 char:1
      • iwr https://github.com/spicetify/spicetify-cli/blob/master/install.ps ...
      • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      • CategoryInfo : NotSpecified: (:) [Invoke-WebRequest], DirectoryNotFoundException
      • FullyQualifiedErrorId : System.IO.DirectoryNotFoundException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

    So i tried changing it to : iwr https://github.com/spicetify/spicetify-cli/blob/master/install.ps1 -Outfile test.htm

    and HERE is the Output:

    268251-1.png
    268176-2.png
    268233-3.png
    268223-4.png

    Maybe it can come handy.
    I am literally stuck.

    0 comments No comments

  4. MotoX80 33,296 Reputation points
    2022-12-07T14:22:26.497+00:00

    In your images I can see the script code. That means that the url you use in iwr returns a web page as it 's supposed to do, and not just the script itself.

    But it worked and didn't give you the "unable to connect" error that you first reported. And if you browse that page with Edge or Chrome, you can just copy and paste the script. You don't need to use invoke-webrequest.

    Try this: Launch Powershell_ISE and paste in this code and run it.

    cls  
    Set-Location $env:TEMP  
    Remove-item "test.txt"  
    # $resp = iwr https://github.com/spicetify/spicetify-cli/blob/master/install.ps1   
    $resp = iwr -useb https://raw.githubusercontent.com/spicetify/spicetify-cli/master/install_curl.ps1  
    "HTTP status code = {0}" -f $resp.StatusCode   
    "HTTP status desc = {0}" -f $resp.StatusDescription  
    "Content length   = {0}" -f $resp.Content.Length  
    "Here is what we downloaded."  
    $resp.Content | Out-File "test.txt"  
    notepad "test.txt"  
    

    It should look like this.

    268207-image.png

    Try different url's until you get what you want in test.txt. If you see HTML encoding then the web address is "browsing" a page and not downloading a script.

    0 comments No comments

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.