Test access to an HTTPS website from remote computers

This topic contains 5 replies, has 2 voices, and was last updated by  Tony Pagliaro 2 years, 1 month ago.

  • Author
  • #39256

    Tony Pagliaro

    Hello PS Gurus,
    I would like a way to accomplish what the following command does, but on a remote computer assuming that remote computer has PSRemoting disabled and running powershell v2 and .Net 4.0. (or higher).

    $eaTemp = $ErrorActionPreference
    $ErrorActionPreference = 'stop'
    Invoke-WebRequest -Uri "https://sub.domain.com" | %{$_.StatusDescription}
    $ErrorActionPreference = $eaTemp 

    This gives me good result on MY LOCAL computer. I can add the -Session param but only if the remote PC has PSRemoting enabled.

    Is there a way I could get a similar result for a (batch of) remote computer(s) without a session?

  • #39257

    Don Jones

    You wouldn't have a way of sending the command to the remote computer.

  • #39258

    Tony Pagliaro

    Maybe using some other command to accomplish the same test?

    This psexec method below sort of worked, but the result isn't pretty.

    $r = psexec \\ComputerName powershell "invoke-webrequest -uri https://sub.domain.com' | %{$_.statusdescription}"

    ...returns what appears to the the "select *" result but as a string (ew).

    This gives Null if failed, True if OK.

    Select-String -InputObject $r -SimpleMatch 'StatusDescription : OK' -Quiet

    It's ugly but I think I have a working concept. Any way to make this happen using TCP or telnet commands, or com objects?

  • #39259

    Don Jones

    That's like saying you wanna drive someplace but don't want to use a car :). That's the command I would use; it's ugly because psexec is having to deal with formatted output that wasn't meant to be handled that way.

    But yeah, it's a string. That's all psexec can do.

    Apart from just directly using what Invoke-WebRequest is using under the hood, I don't know what else you'd do. That's how .NET does web queries.

    I mean, you could check the status code of the response to see if it's 200 or an error, and output something, I guess. But you're using 21st century technology in a 20th century context. It's gonna be ugly.

  • #39260

    Don Jones

    And yeah, you could telnet to port 80. Http is just telnet under the hood.

  • #39266

    Tony Pagliaro

    OK 🙂

You must be logged in to reply to this topic.