Thursday, April 21, 2011

Scripting Games Beg6

Here is my posting of Game 6 of the 2011 Scripting Games. The requirements were to write a script that would search the WindowsUpdate.log file for any Fatal errors. Bonus points were awarded for brevity. If aliases were going to be used an explanation of the alias was needed.
# Alias: gc = Get-Content
# sls = Select-String
# also using the Environment variable to find the WindowsUpdate.log file

gc $env:systemroot\windowsupdate.log | sls "Fatal"
The Get-Content command is pretty simple. It prints the file specified by its default argument. I shortened the code by using the $env variable to access the systemroot variable path. If your not too familiar with the Environment Provider you can enter the following command to see whats available thru it.

cd env:
ls

On my system "SystemRoot" goes to C:\Windows. So $env:systemroot\windowsupdate.log resolves to:

C:\windows\windowsupdate.log

I then pipe the output of the log file to select-string cmdlet and search for any text called "Fatal".
This was probably the easiest of all the games and really didn't take much time to come up with this solution. This challenge was probably the biggest reason why I regret not entering the Advanced Games. 8)

No comments: