I just want to start by defining the server up time. server up time is defined as the time since the server had been restarted.
During my work in data center administration in big companies, and as part of my role of leading the data center operations team, It was so hard for me to verify that Windows updates are distributed to data center servers, installed, and then restarted. The reason behind this, is simply because some critical servers cannot be configured to be restarted automatically upon Windows update installation.
The solution at that point is to coordinate with application owners to do the restart on their monthly maintenance window. If you are managing a very large data centers, you cannot just trust those people to restart their servers. You need a way to quickly connect to a remote server or servers, and get the up time information. This will give you an answer to a simple question “What is the up-time for the server, and when it was restarted?”
This function will take a server name or array of server names, and return server up time in form of TimeSpan data type. TimeSpan data type is the best way to return such information, because the calling function can inspect the outcome, and construct the information it needs from it. It is like returning row data to the requester, and he can shape it the way he like.
Why this is different ?
What makes this script different than other scripts is two things:
- Faster: instead of getting all WMI data from all the information Win_OperatingSystem name space and then pick the server up time, we will only get the server up time property from the remote server from the beginning, so less data across the wire.
- Returns object with two properties: we will return an object per computer that contains two fields
- ComputerName as a string
- UpTime as a timespan.
- Better error handling: even if there is trouble getting WMI data from the remote computer, the uptime property will be replaced with “n/a” instead of throwing exception.
- Returns TimeSpan: UpTime property will be TimeSpan, so you can browse its properties and get uptime in days, minutes, seconds, or even more accurate information.
- Flexible Input Data: can take input from the pipeline in form of single server or array of server names.
Get server up time the smart way
You can get this wrapper function from TechNet Gallery, and I appreciate if you can rate it with full stars.