Judge Notes: Event 1 - and Thank you for participating!

It’s amazing to see all the participants this year joining in the Scripting Games. I have so much respect for everyone willing to share their ideas and contribute to the games -  Thank you! – it takes a lot of guts to put your ideas in front of everyone and be judged. You ARE helping the entire community – You DO have my respect.

I want to start this first blog entry with my perspective and offer a little help along the way. Some of the things I’ve seen have really impressed me – I’ve even learned a few new tricks – and some things I’m seeing should not be happening. I’ll focus on the beginners challenge for Dr. Scripto in this blog.

Many folks attempted to solve this problem in a one-liner. There is nothing wrong with that, but I noticed many people going through some pretty chewing code to make the one-liner work. Don’t be afraid to make a script if your nesting Foreach-Object inside Foreach-Object. 😉

A couple of gottacha’s –

  • Make sure you understand the capabilities of the cmdlet’s that you’re using. It can make your solution easier to write, easier to read, and just plain easier. I saw a lot of folks using Get-Childitem twice like this:

get-childitem C:\Application\Log -directory | get-childitem -name "*.log"|

Many folks did three one-liners, one for each folder. Get-Childitem can make this easier with the –recurse parameter.

 Get-ChildItem -Path C:\Application\Log -filter *.LOG -recurse |

  • Careful with those aliases my friend. I know that many people posted the code as if they were sitting at a console and solving the problem. In interactive mode, you often use alias’s to make the typing shorter – and if you posted a one-liner that used aliases, I forgave you for that. But if you posted a full script and used aliases – gottacha. In other words, when you script, try to be as verbose as you can. It makes readability easier and future maintainability far easier. As an example, I saw a lot of this:

Gci c:\application\log –filter *.log –recurse | ?{something} |%{something}

I don’t know about you, but this is not easy for someone else to read and should not be in a script. Tab completion makes is fairly easy for you to keep things readable without a lot of additional typing.

Get-ChildItem –Path c:\application\log –Filter *.log –Recurse | Where-Object{something} | Foreach-Object{something}

  • And my last tip for this blog? I can’t believe I’m still seeing this after all these years - and maybe I’m overly sensitive to it - but please stop using WRITE_HOST!

Try Write-Output instead, or if you want to just document your code, how about Write-Verbose. If you want to warn the user, then Write-Warning. All of these are far better, more flexible, and less problematic going forward. Please, no more scripts with write-host. I have a tendency to just ignore your solution and vote down your script.

Again, to everyone – thank you for having the courage to participate and join the fun in the Scripting Games. We all (myself included) learn so much from this!

Knowledge is PowerShell,

Jason

About the Author

Jason Helmick

Jason is a 25-year IT veteran and full-time author for Pluralsight. He is an avid supporter of the PowerShell community as board member and CFO of PowerShell.Org. He is the author of Learn Windows IIS in a Month of Lunches and contributing author to PowerShell Deep Dives, along with a columnist for TechNet Magazine and many other industry publications. He is a frequent speaker at many conferences and can be contacted on Twitter: @theJasonHelmick