Author Posts

May 18, 2016 at 3:09 pm

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?

May 18, 2016 at 3:14 pm

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

May 18, 2016 at 3:45 pm

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?

May 18, 2016 at 4:12 pm

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.

May 18, 2016 at 4:13 pm

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