Beginner Practice for 2013 Scripting Games

Beginner Practice for 2013 Scripting Games

  • Comments 1
  • Likes

Microsoft Scripting Guy, Ed Wilson, is here.  Today we have Don Jones, from www.powershell.org and a practice event for the Beginner category of the 2013 Scripting Games.

Scripting Games logo

This is a practice event. You will not submit this event to the actual Scripting Games, and no official judging will be available for this event. If you would like to post your solution for peer review, please do so in The Scripting Games forum on PowerShell.org or in another venue of your choosing. It is your responsibility to solicit peer reviews from the community; no judges or moderators are scheduled to provide reviews for this practice event.

Image of Dr. Scripto

Dr. Scripto is in a quandary. On one hand, he has a request to calculate the current uptime for a set of servers in his domain. On the other hand, he’d love to go see the new Michael Bay movie. Query uptime, or watch exploding robots?

Easy choice. While Dr. Scripto enjoys a wonderful motion picture, you get to figure out the uptime thing.

You’ve been given a list of server names and IP addresses in a text file, C:\Servers.txt. It contains one name or IP address per line. You need to write a command that displays each computer’s name (even if you were given an IP address, you must display the name) and the number of hours, minutes, and seconds the computer has been online since its last restart. Your output should consist of four properties with hours, minutes, and seconds broken out into their own individual properties.

You can be assured that all of the servers in the list are in the domain, and that you’ll have authority to query them. They’re all running Windows Server 2008 R2 or later, and they all have Windows PowerShell 3.0 installed. There are no firewalls or other blockages between you and those computers, and your command can assume that all of the servers are online and reachable. (If one isn’t, an appropriate error message should display, but it need not contain the failed computer name or IP address.)

Your command should be as concise as possible—a one-liner, if you think you can do it, although you’re welcome to use full command and parameter names for better readability. The output of whatever command you write must enable someone to pipe the output to a CSV file, XML file, or HTML file, if they so choose; but you do not need to provide those functions in the command you write.

Hint   There’s a commonly-used WMI class that contains the most recent computer start-up time. There are also event log entries related to total uptime.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • hallo there! Where will you publish the solutions? :)