The easiest way would be to use the Test-NetConnection cmdlet.
Script to check a server is up or down
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.
5 answers
Sort by: Most helpful
-
-
Andreas Baumgarten 108K Reputation points MVP
2022-04-07T21:44:48.657+00:00 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)
Regards
Andreas Baumgarten -
Rich Matheisen 46,551 Reputation points
2022-04-07T22:48:15.813+00:00 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.
-
EdWin 121 Reputation points
2022-04-07T20:08:57.063+00:00 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
-
MotoX80 33,376 Reputation points
2022-04-07T23:38:49.163+00:00 Or purchase a commercial product like Servers Alive.
https://www.woodstone.nu/salive/
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.