Learn about Windows PowerShell
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
4/16/2012 12:01 AM
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.
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 firstname.lastname@example.org, 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
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?
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?
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"
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!!!
Still waiting for some Ed comment...:)
@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.
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
@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.
@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.
@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.
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?
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?
@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.
@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!
@K_Schulte you are right, that date is the date that the system came online -- it corresponds to the days, hours, minutes and seconds.