Check a web URL

Welcome Forums General PowerShell Q&A Check a web URL

Viewing 4 reply threads
  • Author
    Posts
    • #163470
      Participant
      Topics: 15
      Replies: 68
      Points: 306
      Rank: Contributor

      I have a bunch of servers and I want to check if the URL https://servername:portnumber is opening or cannot load anything.

      I tried using Invoke-WebRequest -URI https://servername:portnumber, however it says:

      The underlying connection was closed. An unexpected error occurred on a send.

      When I try to access this URL in the browser it works. However I want to find if the url can load or could not load using powershell. Any suggestions on how to achieve this?

    • #163491
      Participant
      Topics: 12
      Replies: 525
      Points: 1,233
      Helping Hand
      Rank: Community Hero
      Test-NetConnection ServerName -Port 443
      
    • #163494
      Participant
      Topics: 15
      Replies: 68
      Points: 306
      Rank: Contributor

      Thanks. Is Test-NetConnection the same as accessing the URL in the browser?

      • #163518
        Participant
        Topics: 1
        Replies: 64
        Points: 363
        Helping Hand
        Rank: Contributor

        Replied to wrong person…

    • #163521
      Participant
      Topics: 1
      Replies: 64
      Points: 363
      Helping Hand
      Rank: Contributor

      Are you using a self signed cert on the server?  If so, powershell will blow up on that.

       

      I’d recommend using curl for windows, .\curl.exe -k <url>, you can feed it using powershell.  Powershell has curl set as an alias to invoke-webrequest, so you’ll need to fully qualify the location AND put .exe at the end to force it to use curl.

       

      $url=(whatever)
      foreach ($u in $url){
      .\curl.exe -k $u}
    • #163629
      Participant
      Topics: 15
      Replies: 68
      Points: 306
      Rank: Contributor

      Thanks for the reply. There is no certificate in the picture, however when accessing the url in the browser I get a certificate error ( that the url is not trusted and do I want to continue), I can just accept the warning and continue and that will display the page.

      • #163743
        Participant
        Topics: 1
        Replies: 64
        Points: 363
        Helping Hand
        Rank: Contributor

        umm…that means there is a certificate then.

        Powershell doesn’t like ‘bad’ certs (ie any cert that throws an error in the browser). I’ve seen some ways that are supposed to work around it, but none have worked for me. I would still recommend using curl for windows.

Viewing 4 reply threads
  • The topic ‘Check a web URL’ is closed to new replies.