2012 Scripting Games Beginner Event 6: Compute Uptime for Local Computer

2012 Scripting Games Beginner Event 6: Compute Uptime for Local Computer

  • Comments 17
  • Likes

 2012 Scripting Games badge

Summary: In Beginner Event 6, you are required to compute the uptime for the local computer.

About this event

Division

Beginner

Date of Event

4/9/2012 12:01 AM

Due Date

4/16/2012 12:01 AM 

Event scenario

You are the main network administrator for a small company. As such, your duties consist of a variety of functions, including assisting the Help Desk when they get behind. Recently, your manager has become concerned about server uptime. He wants you to write a script that will display how long a server has been “up.” He said that he is not concerned with anything fancy—he just wants a general idea. The only real guidance he provided for the task is, “Use WMI. There is a class called Win32_OperatingSystem that should do the trick for you. Tell me the server name, and how many days, hours, and minutes the server has been up.”

The output that is shown in the image that follows meets the boss’s requirements.

Image of command output

Design points

  • Your solution only needs to run locally.
  • Your script should be easy to read and easy to understand.
  • Your script is only concerned with the uptime for the local server, calculated with the current time. Do not worry about time zones or about comparing up times with different computers.
  • Pay attention to the formatting of the output and the script itself.

2012 Scripting Games links

2012 Scripting Games: All Links on One Page

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. Good luck as you compete in this year’s Scripting Games. We wish you well.

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
  • <p>This one wasn&#39;t too difficult. 10 seconds after I submitted my script, I realized I should have done something different that might cause me a point. I guess in the future I will make sure I am super happy with my final script before submitting. Double check everything, and make sure you are completely happy with your scripts.</p>

  • <p>I&#39;m really struggling on this one. &nbsp;Think I&#39;ve found the property I need to use but it&#39;s a string and I can&#39;t figure out how to make it more friendly and able to go into the equation I want it to. &nbsp;Any advice?</p>

  • <p>@Chris-D This is good advice, double check everything and make sure you are happy with your script. I would also add that you have 7 days before an event becomes due, and so you can set it aside for a little bit. Also be careful when submitting the script -- make sure you are submitting it for the correct event!</p>

  • <p>@Mr Killian Wow ... hmmmm... let me see. Use Get-Member and look at both the properties and the methods. You might also want to look at the Hey Scripting Guy Blog to see about working with WMI dates. There may be some links in the study guides for the Scripting Games. I have study guides on the All in One page for several years of Scripting Games. There may be a section about working with dates there.</p>

  • <p>I am kicking myself, I had it all done and just noticed something is amiss. I didnt see it since I normally dont have it set to this value.</p>

  • <p>Just to confirm, the boss asks for minutes but the script output shows seconds. Which should we be using?</p>

  • <p>@Matt Tilford Yes, you are right the boss only asked for minutes, but the output also includes seconds. It is not a requirement, but I threw it in there because I already had the value. You would not lose a point for including extra information -- but you would lose points if your solution does not include the minutes.</p>

  • <p>Wow went off on a tangent on this one and it was getting really complicated before I changed direction and found a much easier way to do this!</p>

  • <p>The design points don&#39;t mention actually using the win32_operatingsystem. If there&#39;s a way around it, can we use that or is it one of the requirements of the script?</p>

  • <p>@Jlsuperman the boss specified that you should use win32_operatingsystem, so that makes it a requiement. </p>

  • <p>I think I&#39;ve figured this one out but after getting 1 star on one that I thought I had nailed I think I&#39;ll sleep on it and check again tomorrow. Triple check is my new mantra.</p>

  • <p>I see my Get-Date is returning 24-hour time when converted to string (no AM/PM). Would I lose a point for not formating to the 12 hour time with AM/PM per your sample output? You mention paying attention to the formatting of the output, but it seems to me it would add unneeded work to format the date for 12hour AM/PM.</p>

  • <p>@Daniel-D 24 hour format will be fine. I do not expect you to calculate AM / PM.</p>

  • <p>By &quot;Up&quot; time, do you mean how long has it currently been running? &nbsp;Or do you mean how long has it been &quot;Up&quot; for the life of the server? &nbsp;I am guessing by the sample output you just mean currently running, but thought I should double check.</p>

  • <p>Quick clarifying question : By uptime you mean how much time the server has been up since it rebooted? Or how much time in general? </p>