2012 Scripting Games Advanced Event 6: Compute Uptime for Multiple Servers

 2012 Scripting Games badge

Summary: In Advanced Event 6, you are required to compute the uptime for multiple servers.

About this event



Date of Event

4/9/2012 12:01 AM

Due Date

4/16/2012 12:01 AM

Event scenario

You are the server lead for a medium-sized enterprise, and your boss has tasked you with computing the uptime of all servers on the network on a daily basis. This information will be stored in a Microsoft Excel spreadsheet for ease of analysis. Because of the large number of servers, the script will take some time to run; therefore, your boss has decided to compute all uptime as of 8:00 AM local time. If a server reboots after 8:00 AM, but before the report runs, the uptime is zero, and it will be factored into the report for the next day. Create a new report file each day for all the servers on the list. An acceptable output is shown in the image that follows.

Image of command output

Design points

  • Your script should be capable of running more than once per day. If it does, it should not generate an error.
  • Create the CSV file in the logged-on users Documents special folder.
  • The file name should use the year, month, and day that the report runs, with the addition of _Uptime to the file. It will appear like the following: 20120409_Uptime.csv
  • The column headers should appear on the first row only. The headings should be ComputerName, Days, Hours, Minutes, Seconds, and Date.

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 

Comments (26)

Cancel reply

  1. Anonymous says:

    Hi Ed, two question straight:

    you have explained, what happens if the script runs post 8am (for example at 10am).

    But could you shell some light on what happens if the script runs at 6am well before 8am?

    Thanks in advance

  2. Anonymous says:


    Agree with you, but i specialy asked about it.

    We see Ed answer… and what we can do?)

  3. mredwilson says:

    @Ryan Ries yes, you can assume that you will impersonate an account that has rights to the remote systems. Offering the option for alternate credentials is not specified as a design requirement in this scenario … it is hard enough as it is. But if you want to add that capability keep in mind that alternate credentials are not used on a local connection, and so you must account for that. Do not make a mistake doing this and cost you your 5 by turning in a script that does not work!

  4. K_Schulte says:

    Hi Ed,

    if we append to the CSV file … we may have more than one entry for one server, if it boots again after 8:00 am!

    I'm stil not sure, that I got everything right.

    Happy Easter!!! btw


  5. mredwilson says:

    @K_Schulte The requirements for the scenario would permit appending to the list 24x60xservers on the list. When I envisioned the scenario, I figured it would be run as a scheduled job and would only run once a day (at perhaps 8:30 AM or so depending on how long the reports takes to complete, and when the CIO wants the report). I like your suggestions, especially only appending if they have changed. The reason I do not want to ignore a server that has booted up after 8:00 AM is for the very reason I envisioned … if you run the report once a day at perhaps 8:15 AM, and if a server has booted after 8:00 AM, then you would be missing that server (or servers) from that days report. This is the reason for adding 0 days, 0 hours, 0 minutes and 0 seconds to the list so that the server would stand out on the report.

  6. Are we still assuming impersonation for getting the information from the remote systems, or do we need to provide a mechanism for providing credentials?

  7. K_Schulte says:

    @Ed -> Roman:

    Are you sure that the date column represents the date, the report was run?

    It doesn't fit to the report name, if you were right! Looks like: A straight contradiction 🙂

    And: why include the time the report was run to each report row if it is contained in the filename?

    Usually I would add a header line, like "Server Report generated at 3/8/2012 8:15 am"

    To me it would make sense, to add the date of the last Boot up as an additional information …

    it saves the boss time to calculate the last boot up time out of values like:

    1234 hours, 34 minutes, 21 seconds from the last report run!


  8. mredwilson says:

    @Roman Prosvetov This means that you can ignore uptime that would be reported after 8:00 AM  but before the report runs. The next time the report runs, it will pick up the uptime.

  9. mredwilson says:

    @Roman Prosvetov The value in the date column is the day, month and year that the system rebooted.

  10. mredwilson says:

    @K_Schulte yes, you WILL have more than one entry for one server in the file. Suppose the first time the script runs is at 9:00 AM, then you would have all the uptime for the server AS OF 8:00 AM. Next the server reboots at 10:00 AM. Later you run the script again at 2:00 PM. You would NOW have an additional entry in the report. This entry would report 0 days, 0 hours, 0 minutes, and 0 seconds. Because we ignore the uptime AFTER 8:00 AM until tommorow when we would report 22 hours, 0 minutes, 0 seconds because that is the uptime between 10:00 AM when the server rebooted and 8:00 AM the next day when we compute uptime for the next days report.

  11. K_Schulte says:

    Hi Ed,

    thanks for the clarification, but …

    Would you really like to see a server appear mutiple teams in the report file?

    If you start the script each minute … should it append 24 x 60 x (servers in the list)

    entries to the report?

    Or just append entries, if they have changed?

    Or best of all ignore servers that booted up after 8:00 am because they will appear in next day's log anyway

    and their time data will be (wrong and) zero anyway?


  12. mredwilson says:

    @K_Schulte if a server boots at 9:00 AM, and your script runs an hour later, you would report 0 because all uptime is reported as of 8:00 AM that day. Yes you would have two different CSV files. One created when you run the script on the 8th and another report when you run the script on the 9th.

  13. mredwilson says:

    @K_Schulte you are right, that date is the date that the system came online — it corresponds to the days, hours, minutes and seconds.

  14. K_Schulte says:

    Hi Ed,

    this one looks like a really realistic task for server admins!

    And it seems to be of medium complexity, if I got everything right!

    We may assume that Excel is installed on the machine running the report

    and the CSV extension is associated with Excel, if we wamt to display the

    report in the end … I suppose.

    And we shouldn't mind if the report takes some minutes to run … right?


    1) If Ed writes:

    "Create a new report file each day for all the servers on the list"

    I think you can rely on something like a "list of servers" being available.

    2) If you read carefully through the task description you may be able to

    answer the question for yourself, … if I got it right …

    3) I think that the date column represent the "uptime date" value.

    This is not necessarily the same date value as included in the script name.

    If a server is up for 19 hours, 56 minutes and 4 seconds it is likely that

    the Date column will be one day back from the the date part of the CSV file.


    I'm german and no expert in english 🙂

    But: I would describe it as:

    The server is not included in the current report.

    It will be included in next days' report.

    ie: "factored out from todays' report"

    Right, Ed?


  15. K_Schulte says:

    @Ed, @Jason

    I have been mistaken regarding Jason's second point because I thought of "something completely different" 🙂

    When the script runs at let's say: 3/8/2012, 8:00 am and a server has been up for some days our CSV file will include an old bootup date.

    If it boots up at eg. 9 am that very day and our script will run an hour later … this would require to include a new bootup time (8 am)

    in the CSV file for that server, if I finally got it right … 🙁

    btw: What about running the script on 3/8/2012, 8:00 am and 3/9/2012, 2:00 am?

    Would this really require to have two CSV files: 20120308_Uptime.csv and 20120309_Uptime.csv for the essentially same report?

    And in this case, you would have to overwrite the file 20120309_Uptime.csv when our scheduled report for the next day runs at 3/9/2012 8:00 am!

    This way 20120309_Uptime.csv would include last day's report for 8 hours and this day's report for the next 16 hours.

    SO: @Jason – Right! We should ask this question!!!


  16. Anonymous says:

    Wow Ed…thank you that I have looked here before posting a script)))

    let's not joke more so 🙂

  17. Anonymous says:

    test, just lost a long comment 🙁

  18. Anonymous says:

    Still waiting for some Ed comment…:)

  19. Anonymous says:

    1. I still don`t inderstand what value must be in "Date" column.

    2. "The next time the report runs, it will pick up the uptime" you mean a report that will be tomorrow?

  20. Anonymous says:


    I`m not good know english, can you explain me this part of string pls:

    "the uptime is zero, and it will be factored into the report for the next day"

    1. What must be factored into next report?


  21. mredwilson says:

    @Jason No your script does NOT need to be able to query for all of the servers on the network. You script DOES need to support a computername type of parameter. Yes you should append to the CSV file. You do not want to overwrite it. No. The sample screen shot reports hours and minutes, but not days. The report was run AFTER 8:00 AM, and the uptime on the server AS OF 8:00 AM was 19 hours 56 minutes and 4 seconds.Which would mean that the server had been rebooted sometime around 1:00 or 2:00 pm on March 7, 2012 (if my math is correct from the top of my head). This, actually is a good example of what the report does. It looks at how long a server has been up AS OF 8:00 AM on the day the report runs. IF the server had been rebooted AFTER 8:00 AM but BEFORE the report runs, then it would report 0 days, 0 hours, 0 minutes, 0 seconds.

  22. Jason Stangroome says:


    Some clarifications please:

    1. "all servers on the network" – does the script need to query for all servers on the network or will this list be passed to the script?

    2. "Your script should be capable of running more than once per day" – should the script append to the CSV or overwrite it if it has already been run?

    3. The example screenshot shows the file refers to March 7th but the Date column shows March 8th. Can I assume this is because the Date column contains the time when the uptime was calculated and in this example the script was run after midnight but before 8am on March 8th?



  23. Scott Heath says:

    Wish I had waited before submitting and read more comments.  I thought the date conflict in the picture was just an oopsy.  See as it's ahrd to run a report on 3/7 and predict a computer reboot on 3/8.

    I made the assumption it was the date the report was run, even though that didn't make much sense.  Doh.

  24. Tim Parkinson says:

    D'oh from me too. I fell into the same trap as Scott. There go my points!

  25. Hemanth.Damecharla says:

    So, I have been wondering what should we report as up time when the report runs between 12:00 AM and 8:00 AM? Should we report the uptime that we assume it would have at 8:00 AM? Or, report the actuals?

  26. Josh Feierman says:

    Hey Ed,

    'Fraid I'm a little confused by the comment "The value in the date column is the day, month and year that the system rebooted." If that's the case, and the screenshot is of a report run on 3/7, how could the computer have rebooted on 3/8? Is that just an oops or am I misunderstanding what you meant?



Skip to main content