Test access to an HTTPS website from remote computers

This topic contains 5 replies, has 2 voices, and was last updated by Profile photo of Tony Pagliaro Tony Pagliaro 4 months, 1 week ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #39256
    Profile photo of Tony Pagliaro
    Tony Pagliaro
    Participant

    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'
    Try{
    Invoke-WebRequest -Uri "https://sub.domain.com" | %{$_.StatusDescription}
    }
    Catch{'FAIL'}
    $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
    Profile photo of Don Jones
    Don Jones
    Keymaster

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

    #39258
    Profile photo of Tony Pagliaro
    Tony Pagliaro
    Participant

    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}"
    $r
    

    ...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
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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
    Profile photo of Don Jones
    Don Jones
    Keymaster

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

    #39266
    Profile photo of Tony Pagliaro
    Tony Pagliaro
    Participant

    OK 🙂

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.