Mr. Roboto

Can You See Me Now?

Sometimes, all you want is a quick reassurance that your server farm is OK. Here's a script to give you some peace of mind.

If you're responsible for maintaining a larger server farm, you've probably invested in some sort of monitoring solution. You want to know at the earliest opportunity if a server goes down or starts misbehaving. Even admins in small to midsize shops might like a tool that offers this peace of mind. This month, Mr. Roboto has a very simple PowerShell script called Display-ComputerStatus.ps1, which you can download from the script library at jdhitsolutions.com.

In order to run this script, you'll need PowerShell 1.0 installed on your computer -- or wherever you want to run it -- and access to the Windows Management Instrumentation (WMI) service on any remote machine you want to monitor. You'll also need a text list of computer names that you want to monitor, with one computer name per line. If you have scripting experience, you could modify the script to pull names from Active Directory, but I wanted to keep this simple. Download the script and rename it with a .PS1 file extension. Run it from your PowerShell console:

PS C:\Scripts > .\Display-Comput
erStatus.ps1

The first thing you'll notice is the script creates a graphical display. PowerShell doesn't have to be console-based alone. I created this form using PrimalForms, the free forms-builder tool from Sapien, downloadable from the Free Tools section of Primaltools.com. I've also included the source file if you want to edit it yourself. To use the form, enter the path and file name of your text file and click the Get Status button.

How It Works
First the script pings each computer. If the computer can be pinged, a WMI query is executed against the computer to query the Win32_OperatingSystem class. From this class, the form will display the operating system name, Service Pack and when the computer was last booted. From the last boot time, a total uptime value is calculated and displayed. The script has no provision for alternate credentials, so you need to run it with an account that has administrator rights on all the computers in your list.

Results will be displayed in green text. If the initial ping fails, the results will be displayed in red text. The default display is sorted on the computer name. Clicking column headings won't change the sort, but you can drag and drop to reorder columns. You can also resize the form to stretch out column headings or to hide empty datagrid space.

By default, the script will check all the computers again in five minutes. You can change the interval in five-minute increments up to 60 minutes. One point to remember is that any changes to the interval value won't take effect until the next refresh cycle -- though you can change the value and click Get Status to start a new refresh cycle.

I also added a feature that I hope you'll find useful. Double-click on any computer name in the grid and the computer-management console will launch, connecting to the remote computer. Not only can you see the status of critical servers at a glance, you can also easily manage them.

Scripting in Action
If you open the script file in a scripting editor, such as PrimalScript 2009, you'll notice many Write-Debug commands. These lines display information about what the script is doing, what value a particular variable might have and other useful information. I can turn these lines "on" by setting the $DebugPreference variable to Continue. My script takes a parameter, -debug, that if specified will turn on the debug pipeline and display this debug message:

PS C:\Scripts > .\Display-Comput
erStatus.ps1 -debug

The script has error handling, and will write warning messages for computers to which it can't connect. If you prefer not to see these warnings, use the -NoWarning parameter when running the script:

PS C:\Scripts > .\Display-Comput
erStatus.ps1 -nowarning

This script won't replace a full-featured network-monitoring solution, but it may be just what you need for a quick status and sanity check.

If you have any questions about this script or using PowerShell, please stop by the forums at Scriptinganswers.com.

About the Author

Jeffery Hicks is a multi-year Microsoft MVP in Windows PowerShell, Microsoft Certified Professional and an IT veteran with almost 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He works today as an independent author, trainer and consultant.

comments powered by Disqus

Reader Comments:

Sun, Jun 7, 2009

http://jdhitsolutions.com/resources/scripts/display-computerstatus.txt

Wed, Apr 22, 2009 John Smithenson

Steve, I did "RTFM" DA.
The FM states: "Display-ComputerStatus.ps1, which you can download from the script library"

Searching the ENTIRE SITE you will not find "Display-ComputerStatus.ps1" anywhere because it is listed under the Column name "Can You See Me Now".
While this is obvoius now, I was looking for "Display-ComputerStatus.ps1" as the FM clearly states.

Looks like YOU didn't RTFM". :-)

Tue, Apr 21, 2009 Steve MDdatacor

Someone from Smithenson needs to clean his glasses. It took me about 2 or 3 mouse clicks to find the script. I'll agree that the navigation could be better, but I actually read the instructions and found the script very quickly.

Maybe next time he'll "RTFM". :-)

Tue, Apr 14, 2009 Jeffery Hicks Anonymous

I agree the jdhitsolutions site needs a total overhaul and I'd love to offer a more direct link but unfortunately given production schedules its not that easy.

As for the computer list, that's what the PowerShell script uses. When you launch the script you get a graphical interface. Enter the path to your text file of computernames and click the Get Status button.

Tue, Apr 14, 2009 Stuart from FDOE Anonymous

There is mention of needing a list of computer names, but no information on what to do with it?

Thu, Apr 9, 2009 John Smithenson

"Mr. Roboto has a very simple PowerShell script called Display-ComputerStatus.ps1, which you can download from the script library at jdhitsolutions.com. "

Really? Where?

Your "personal" site is so poorly designed it takes a while to find anything. How about instead of trying to increase traffic to your "personal" site you help everyone and put a link to the actual file.

Add Your Comment Now:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Comment:
Please type the letters/numbers you see above

Redmond Tech Watch

Sign up for our newsletter.

I agree to this site's Privacy Policy.