Check a web URL

Welcome Forums General PowerShell Q&A Check a web URL

This topic contains 6 replies, has 3 voices, and was last updated by

 
Participant
2 months, 2 weeks ago.

  • Author
    Posts
  • #163470

    Participant
    Topics: 10
    Replies: 48
    Points: 200
    Rank: Participant

    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: 9
    Replies: 423
    Points: 676
    Helping Hand
    Rank: Major Contributor
    Test-NetConnection ServerName -Port 443
    
  • #163494

    Participant
    Topics: 10
    Replies: 48
    Points: 200
    Rank: Participant

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

    • #163518

      Participant
      Topics: 1
      Replies: 59
      Points: 328
      Helping Hand
      Rank: Contributor

      Replied to wrong person...

  • #163521

    Participant
    Topics: 1
    Replies: 59
    Points: 328
    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 , 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: 10
    Replies: 48
    Points: 200
    Rank: Participant

    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: 59
      Points: 328
      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.

You must be logged in to reply to this topic.