PowerShell: Probe Remote Machine for Its OS Type

function probeOsType($server){
	$ping=test-connection $server -count 1
	$ttl=$ping.ResponseTimeToLive
	$osType=switch($ttl){
 			{$_ -le 64} {"Linux"; break} # MacOs TTL default is also 64, but we don't count toys
 			{$_ -le 128} {"Windows"; break}
 			{$_ -le 255} {"UNIX"; break}
		}
	return $osType
}

probeOsType REMOTECOMPUTER

Leave a Reply

Your email address will not be published. Required fields are marked *