Check a web URL

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?

Test-NetConnection ServerName -Port 443

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

Replied to wrong person…

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.


foreach ($u in $url){
.\curl.exe -k $u}

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.

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.