Learn about Windows PowerShell
Summary: Beginner Event 6 of 2011 Scripting Games uses Windows PowerShell to find Windows Update errors.
About this event
Date of Event
4/11/2011 12:01 AM
4/18/2011 12:01 AM
On your home computer, you notice that you have not been receiving Windows Update notifications. You are running Windows 7, and you configured Windows Update to download and install updates automatically, but you have not seen the update icon for a long time. After doing a little research on the Microsoft TechNet site, you discover that there is a WindowsUpdate.log file in the %systemroot%\Windows folder (on my computer that path is C:\Windows\WindowsUpdate.log). You decide to use Windows PowerShell to parse the WindowsUpdate.log file and look for fatal errors. You hope that discovery of fatal errors and subsequent recourse to the Knowledge Base articles on the Microsoft TechNet site will enable you to fix Windows Update on your computer, and bring your machine back into security compliance. The following image illustrates an appropriate output for this scenario.
2011 Scripting Games: All Links on One Page
Submit your scripts on PoshCode
Support our Sponsors!
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
<p>another 1point-script seems my scripts work only in good old germany ;-)</p>
<p>seems i found out why it doesn´t work.</p>
<p>when you select the sourcecode with your mice, copy it and paste it directly in the powershell it puts everything in one line....</p>
<p>if that´s your failure, it sucks</p>
<p>Not specifically true. Some judges are deducting points from scripts that work, but do not adhere to the best practices that are detailed in the Judging Criteria. You should review those and adjust accordingly. Not all judges are doing this, but the ones that are grading consistently that way, so it will not affect your overall standing. We had a long discussion last week about grading among the 30 judges. </p>
<p>This is NOT the issue. See my comment to @lol ... your script might very well work, and some judges deduct points. I am going to post a blog that lists the judges comments "in general" very soon. I started the process with my two weekend posts. The one line thing, is only a feature of certain versions of Internet Explorer. There is a download button (availble to judges) that lets me download a script into notepad. I then copy it into the ISE and begin my grading. Some judges double click to copy and that is why you might not see a download of your code. </p>
<p>As per my comment on my script submission - the pictured output returns a warning along with the fatals - yet the outline suggests fatals only?</p>
<p>I suspect this is because the search string is not case sensitive and therefore picks up on the word fatal in the warning message - what should the script look for, all references to the word fatal or just fatal logs?</p>
<p>(I coded based upon the first - but commented that I would amend this to only return fatal entries not anything with fatal within the line)</p>
<p>Clarity please :)</p>
<p>The output is an appropriate output, it is not the required output. I do not say that your output must look like this, it is merely a sample of something that would work. For example, if you are returning all of the fatal errors, but also getting a few warning messages, then you are in fact returning the fatal errors. I do not say that you must ONLY return fatal errors. In fact, you will see that the guidelines for THIS event specifically state that that I DO NOT want you to write a LOT of complicated code. This scenario is one in which you are troubleshooting a specific problem. THIS WILL BE a ONE OFF script ... I WANT you to use aliases. Extra points are given FOR THIS EVENT for shortness of code, and simplicity of syntax. Therefore if you get something that WORKS go with it. You will NOT get extra points for this event if you are writing long convaluted code. In fact, I might very well give you a single star because you did NOT meet the requirements of being simple and compact! This event is COMPLETELY different than the other five you have seen to date!</p>
<p>I understand what you are after - however the output above threw me as the Warning is "not fatal"...?</p>
<p>I submitted a short code (though I didn't/don't use aliases - its hardly a long bit of code anyway) with a comment regarding an addition I would put if it was my log I was parsing :)</p>
<p>@Stephen Croft excellent ...sorry if the output threw you ... </p>
<p>Trying to catch up. I will freely admit I did run the get-alias | select-object Name, Definition | out-printer and was going to hang the output on the cabinet above me, but it took two pages to print and there is a ton of white space where if I had Name, Definition, Name, Definition it would all fit on one sheet with two sets of columns. Any ideas on how to set up a table with multiple columns of the same header and the info just "wraps" to the next set of columns? I know I could export it out to excel and change it that way.</p>