I must say it feels like it was ages ago when we started games, but we are almost at the finish line. I have no idea who is going to win the whole thing, but I have few candidates in mind that did wonderful job and quite frankly: I was learning from them, not other way around. Looks like I’m getting rusty with whole this “scripting” thing.
I’ve done grading Event 6 early – not because I’m so fast, it’s because there were less entries than in previous events. Not sure why… Maybe people felt like this event was pushing workflow down their throat, and wanted to dodge the bullet? Anyways: lets look at some things I liked and didn’t like about this particular event. As usually, I will start with beginners category.
Beginners: like.
First of all – I really enjoyed reading all the entries where authors used everything that PowerShell could do for them. Perfect example of that:
Get-DhcpServerv4Lease -ComputerName DHCP1 -ScopeId 10.0.0.0 -ClientId (Get-Content -Path C:\Mac.txt)
It uses everything that Get-DhcpServerv4Lease has to offer and gets list of IPs in single call.
Another thing: very good use of .NET constructors to created PSCredential objects using known usernames and password. Some people tried to make it too simple (passing plain text there simply won’t work), but most of attendees knew what they were doing.
Next thing: using PowerShell like a shell. If you are running your script on older OS and can’t be sure you have DHCP module handy – you can use older tools and get away with it. I’ve seen few solutions where netsh was used to get the same results. But if you can use this module – don’t hesitate. I admit that I haven’t really tried to use it against older systems, or use –ComputerName parameter on it, so I was a bit surprised to see that it works just fine with older servers (I tested on Windows 2008 Core and above). But knowing that you can get some info using our friend netsh can be life-saver.
Beginners: dislike.
Filter left applies, also here. I know we expected only few IPs as a result, but you really should try to use parameters on cmdlet (if they exist) rather than do the filtering on your side, using Where-Object.
Also: PowerShell is object based, I can’t see any value in doing this:
Get-DhcpServerv4Lease -ComputerName DHCP1 -ScopeId 10.0.0.0 -ClientId $_ | ft IPAddress >> C:\ips.txt
Just to do that next:
$IPAddrPattern = ‘\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b’ Select-String -Path C:\ips.txt -Pattern $IPAddrPattern -AllMatches | ForEach-Object {$_.Matches} | ForEach-Object {$_.Value} | Sort-Object | Get-Unique | Out-File c:\ipsready.txt
You already got unique lists of IPs from first command, why pollute c:\ with files that are not really needed anyways?
Finally: using Get-Credential if your boss gave you username and password is – in my opinion – wasting his time. I guess people didn’t wanted to save passwords in plain text inside a script, but if you are told to do it (in my opinion – we were) – you just do it, even if you feel it’s a bad idea.
Advanced – just a summary… 
There were very few scripts in this category, and most of them were similar. Few things that were great in my opinion:
- using #requires for module, if used inside the script
- using regex “yadda ,yadda” style to “hide” password
- giving option to specify other credentials by setting default value to the one provided
- implementing SupportsShouldProcess
- smart implementation of workflows
I also noticed that most of people considered what may go wrong, like using TrustedHosts to enable PSRemoting by IP addresses to computers outside domain.
I found only few things I didn’t like. There were two scripts that couldn’t work because of relatively small mistakes related to use of $MACAddress – not really something I could see as good script, for me it’s really important to get result. One script that.. was not script at all, just a comment. One function with verb “Provision”. And one script that had no comment based help. And that would be it…
The end…
So – we are done with Scripting Games for this year. The only think that left is: getting to know the winners in both categories, and waking up at 3:30AM at some point to listen live to PowerScripting Podcast, where they will be invited as a guests. In other words: fun, fun, fun.
I hope you enjoyed the games this year and learned few new things. I sure did learn a lot and would like to thank you guys for participating and showing me how things can be done better.