Learn about Windows PowerShell
Summary: Advanced Event 1 of the 2012 Scripting Games asks you to review a coworker’s script.
About this event
Date of Event
4/2/2012 12:01 AM
4/9/2012 12:01 AM
You work as a network administrator for a large company. You are part of a team of other network administrators that monitor several mission critical applications. Your coworker has convinced your boss that he knows everything about Windows PowerShell. As a result, whenever any scripting needs to be done, he always gets the nod. Recently, however, your boss has begun to have some doubts, and the boss has asked you to do a code review of the script that is shown here:
$notepad = Get-Process notepad
for ($i = 1 ; $i -le 10 ; $i++)
When you run the script, you receive the output that is shown here:
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 email@example.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
@Geathan.A you cannot delete a submission once it is entered. Send me an email to Scripter@MIcrosoft.com and let me know which category you will compete in. Then tommorow, and the following days, just submit one script in the category you decide you want to compete.
this is not too enlightening!
I n´know it might be stupid ... but: If the boss wants to have exactly this kind of information, my coworker has scripted ... its OK! If the task has been any different ... it's not OK!
So how can we know without a task description? Even the most stupid script may be OK, if it solves the job description!
No way ... Klaus
@K_Schulte that is true, but only if it really meets the needs. If there is an error in the script, then it does not matter WHAT the scenario was, because the script has a problem. If the script does not have any errors, and it appears to work properly, then as you said, it does not matter what the scenario was because even the stupidest script may be ok.
You have boiled it down to the essential question: does the script work or not. If the script works, then you have to assume that it is what the boss wanted. Look at the name of the script, look at the output from the script. Look at the code. Is it all proper? If everything is fine, then you would tell the boss that there are "no changes" required. If there is a problem, then you will make the minimum changes required to cause the script to function properly. The task is essentially a troubleshooting task.
Part of being an advanced scripter is the ability to make decisions based on the information provided. In this scenario, your boss is counting on YOU to review the script, not vice versa.
Awesome, that's exactly what I was looking for! It sounded a bit like the instructions were contrary to the general judging criteria, and I didn't want to shoot myself in the foot by doing something "correct" like making the code reusable. Thank you for the clarification.
@IamMred - that last comment (thanks on clarification) was from me, forgot to fill in a Name. :)
@Alex McFarland no problem. I am glad the event is beginning to "click" for you.
@Carlos Nunez I invite you to enter the 2012 Scripting Games and to post your answers there. See this page for information about the games and about registering blogs.technet.com/.../the-2012-windows-powershell-scripting-games-all-links-on-one-page.aspx
Enjoying this thread :)
I've decided to enter the Beginner's category, but I am really anxious to see what everyone has submitted for this one. I have an opinion (personal submission in my head) :), but of course I may be really blown away when I see what everyone else has submitted.
Ed, thanks again for having such an involved activity for everyone to participate in!
Talk about over-thinking a solution...(literally)...
Here's a new spin. Monitor Notepad For "10 Seconds" - So I can take this to literally mean "stop" execution at 10.0000 TotalSeconds? Or rely on the likelihood that Get-Process will take (on average) fewer than 100 milliseconds per iteration so at the end of 10 iterations of a for loop I'll still be at less than 10.99999? Wow, yeah I don't think I'm going to wait for confirmation that I'm being too literal...[submit]
And now for something completely different…
Did you ever notice that the Hey Scripting Guys! articles maybe sorted by Most recent / - Views / - Comments?
What do you think will be the top article if you sort by "most comments"? :-)
WOW! We have created a "from zero to 1st place phenomenon" with this this 1st event of the 2012 scripting games!
Here's my follow up thoughts on my previous literal point of view...
Literally accounting for the amount of time passing during each iteration of the script block would dictate that you would also have to calculate the cumulative average time the script block execution itself took so that you could determine before each iteration if, based upon your average script block execution time, you had enough time remaining (in your 10 seconds) to attempt another iteration. Hopefully Ed and the Judges aren't on the lookout for the Robert Frosts among us for this event. For I've lived and fished in the mountains of Montana where taking the road less traveled will only get you eaten by a big bear.
I missed it but now I see.
It was a real trick question. How long is one second?
@IamMred Thanks for the clarifications as they definitely helped me to shift my focus. In the end though I am a little annoyed at myself for not seeing the solution yesterday.
@marcadamcarter dont be too literal. In fact, I do not think that the design guidelines even said monitor for only 10 seconds, but you are on track because it was the name of the script that the (rather dim witted) coworker wrote.