01 June,2012 by Tom Collins
Question: I need to determine the Operating System type of a Linux Server , before deciding a scripted reponse. Is there a quick test to determine if it’s Linux?
Answer:The Test-Connection cmdlet sends Internet Control Message Protocol (ICMP) echo request packets ("pings") to one or more remote computers and returns the echo response replies. You can use this cmdlet to determine whether a particular computer can be contacted across an Internet Protocol (IP) network.
You can use the parameters of Test-Connection to specify both the sending and receiving computers, to run the command as a background job, to set a timeout and number of pings, and to configure the connection and authentication.
Unlike the traditional "ping" command, Test-Connection returns a Win32_PingStatus object that you can investigate in Windows PowerShell, but you can use the Quiet parameter to force it to return only a Boolean value.
$ServerName = "127.0.0.1" $TimeToLive = Test-Connection $ServerName -Count 1 | select -exp ResponseTimeToLive Switch($TimeToLive) {{$_ -le 64} {"Linux"; break} {$_ -le 128} {"Windows"; break} {$_ -le 255} {"UNIX"; break} }
---
If you want to access increased information such as :
name, dnshostname,operatingsystem,operatingsystemservicepack,ip4address,lastlogondate,logoncount
this one-liner using the Powershell cmdlet get-adcomputer and Test-Connection will supply the information
get-adcomputer $ServerName -Property * | Select-Object name, dnshostname, operatingsystem, operatingsystemservicepack, ipv4address, lastlogondate, logoncount, @{label = "PingResults"; Expression = {Test-Connection $_.ipv4address}} |sort lastlogondate -Descending
--
Powershell Scripts for DBA - SQL Server DBA
Powershell - run script on all sql servers - SQL Server DBA
Number of physical processors with Powershell – number of cores ...
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |