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.
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.
Windows for business | Windows Server | User experience | PowerShell
5 answers
Sort by: Most helpful
-
Andreas Baumgarten 131.8K Reputation points MVP Volunteer Moderator2022-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_OperatingSystemshould 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 48,116 Reputation points
2022-04-06T19:27:14.5+00:00 The easiest way would be to use the Test-NetConnection cmdlet.
-
MotoX80 37,676 Reputation points2022-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.
-
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