Script to check a server is up or down

EdWin 121 Reputation points

Hi all,

Please, I have about 200 servers in my environment, both Windows and Linux servers. I need a script to check periodically if these servers are on or off and whether the server is Windows or Linux...

I hope someone can help me.

Thank you.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
4,886 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Rich Matheisen 38,821 Reputation points

    The easiest way would be to use the Test-NetConnection cmdlet.

    1 person found this answer helpful.
    0 comments No comments

  2. Andreas Baumgarten 68,291 Reputation points MVP

    Hi @EdWin ,

    as far as I know it's not possible to get the OS version of a remote computer with just one command.

    But maybe this script helps to get started I haven't tested with a Linux computer, but Get-WmiObject Win32_OperatingSystem should fail on Linux:

    $computer = "localhost"  
    $check = (Test-NetConnection -ComputerName $computer).PingSucceeded  
    if ($check -eq $True) {  
      $os = (Get-WmiObject Win32_OperatingSystem -ComputerName localhost  -ErrorAction SilentlyContinue).Caption  
      if ($os -like "*Windows*") {  
        Write-Output "Looks like a Windows computer"  
      else { Write-Output "Looks like a Linux computer" }  


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Andreas Baumgarten

    1 person found this answer helpful.

  3. Rich Matheisen 38,821 Reputation points

    If you need something that will try (very often successfully) to identify the O/S on a machine, try nmap. There are versions for *nix and Windows. You can tell it to produce a "grepable" file (or one in XML format), and limit the port scan to just use "ping" if you aren't interested in what ports are open. It's extremely fast, especially when you have a sizeable network and the possibility of IP addresses used by machines (like laptops) that may not be online at the time.

    1 person found this answer helpful.
    0 comments No comments

  4. EdWin 121 Reputation points

    Hi @Rich Matheisen ,

    Thank you for your reply. I know this cmdlet, but, I don't think if it works on Linux servers or not, and, I'd like some script where I could identify what is Windows, and what is Linux, do you know what I mean? If with this command I can separate these OS, it would be perfect!

    Thank you

    0 comments No comments

  5. MotoX80 25,656 Reputation points

    Or purchase a commercial product like Servers Alive.

    My experience has been that a server will ping even when the OS is all locked up due to problems like excessive application memory usage. If your organization cares about application availability, then the cost of a monitoring tool is trivial compared to the cost of an outage that impact hundreds of users who can't work and the lost revenue from customers who couldn't place an order with your firm while your systems were dead.

    0 comments No comments