Notes for Event 5
Jan Egil, or Norwegian expert commentator/judge, has posted his learning notes for Event 5: http://blog.powershell.no/2013/05/28/2013-scripting-games-learning-points-from-event-5/
PowerShell articles, tutorials, and guides from community experts.
Jan Egil, or Norwegian expert commentator/judge, has posted his learning notes for Event 5: http://blog.powershell.no/2013/05/28/2013-scripting-games-learning-points-from-event-5/
We’re pleased to announce the winners for Event 4 of The Scripting Games 2013!
Remember that Event 5 is now open for community voting, and that Event 6 opens up near the end of this week. That’ll be your last chance to contribute, and shortly after TechEd we’ll announce the overall winners. Good luck!
Winners: You can log into The Scripting Games Web site and go to your Profile page to see your prize. You will be given a prize redemption code and either a URL where you can redeem it, or an e-mail address of the prize provider (they will need the redemption code). All prizes must be claimed by the end of July 2013. I will list winners by username; if you used your e-mail address as your username, then a portion of that will be truncated for your privacy. Anyone can log in and check their Profile page to see if they’ve won a prize.
Active Directory is one of those things I just love to work with. That’s why I was really looking forward to this event. As always, I learned few things, but still - seen some mistakes that I would like to highlight. As always - you can read about those both in Polish and in English. Enjoy!
Again if you"™re participating in the games this year you"™ve already won! If you"™re not and you"™re reading this post what are you doing! I"™ve watched authors step there game up over the past month, and I can tell you from personal experience the games will make you better at your real job. It"™s like sharpening an axe, an axe made of super juice that can automate the world 🙂
**Well that’s clever!
** I came across this script this morning.
Looking for a great getting-started PowerShell class? Or perhaps you’d like to send a colleague or peer to some PowerShell “zero to hero” training?
We’ve just finished the official beta-teach of Microsoft’s 10961, Automating Administration with Windows PowerShell, and it went _great. _The sequencing of the class was spot-on, and we had an absolutely incredible group of students. Many were n00bs, which was perfect; a couple had “some” shell experience but wanted to learn “the right way.” And they did.
Through a series of 12 modules, you’re led through the basics all the way up to writing your own script. The grand semi-finale has you creating a script that provisions a brand-new, freshly-installed Server Core instance - all without logging on to that instance at all. The high moment for me was when one student, after struggling a bit to get started on the provisioning lab, concluded with a “well, that did it.” Everything came together for him: command discovery, help, scripting, variables, remoting, all of it. He did the task, from scratch, with practically no help. He’s _there. _
10961 replaces MS course 10325, and it will soon be supplemented by a Microsoft Courseware Marketplace title that goes further into scripting, error handling, debugging, and more… what I’ve taken to calling _toolmaking. _We’ll hopefully continue to refresh both courses as PowerShell evolves.
So call your local Microsoft Certified Partner - Learning Systems (“training center”) and see when they’re offering 10961. A bit of caution: this is a class where, unfortunately, an inexperienced MCT will be really challenged. While the course book is a full, almost-500-page book (you’re welcome), it’s tightly timed and you’ll definitely want to check the credentials and experience of whatever trainer is running the class. You can’t just “read the slides” to stay a module ahead of the students on this one.
This class is strongly based upon _Learn Windows PowerShell 3.0 in a Month of Lunches, _in terms of how the material is presented, although the sequence and narrative was altered a bit to better accommodate Microsoft requirements and classroom logistics. I’m really proud of how the course turned out - so if you’ve got folks who need some PowerShell training, tell ’em to look it up. Many CPLS centers offer remote training, too, meaning you can attend from the comfort of your own home or office.
If you take the class, I’d love to hear what you think.
It is all downhill from here folks! Event 4 is in the books and we only have 2 more to go! Everyone has been doing an outstanding job with their submissions and it is becoming clear that people are learning new things and showing some great techniques with their code.
Of course, this doesn’t mean that there isn’t room for improvement with some submissions to make them even better or just some simple mistakes that can be cleaned up to make average submissions into amazing submissions. With that, its time to dive into my notes"¦ You can check out the rest of this article here.
Loved seeing [OutputType([PSObject])] in an entry this morning… that helps the help system document what your script produces. It’s a shame it doesn’t work well with custom type names (since those are a bit of a fake-out on the object), but it’s an attention to detail I appreciate.
I am seeing a little bit of misunderstandings. Keep in mind that the lastLogonTimestamp attribute in AD is the one that replicates, although there is a long possible delay in that replication. There are other “last logged on” attributes that don’t replicate so you can’t rely on them unless you’re querying every DC (pretty inefficient).
Hey, one thing to think about: sometimes simpler is better. For example, instead of adding a dozen lines to check and see if a module exists and can be loaded, just add a #requires comment for that module. Let the shell do that work and spew an error if the module isn’t present. It’ll even force-load the module into memory. Saves lots of steps.
Hey, don’t declare functions as global:Do-This. It’s a neat trick, but you’re polluting the shell’s global scope. Plan to write in-scope functions and make them a script module, so they can be loaded and unloaded. From the Games perspective, “whatever,” but in the real world… don’t pollute the global scope.
A comment I saw: “You should check to make sure the module isn’t loaded before loading it again.” Disagree. The shell does this for you when you use Import-Module. But, doc your module dependency in a #requires, and you won’t have to worry about the module. In fact, the whole theme of “checking to see if the AD module is loaded” appears to be a major point of commenting. I’m a fan of “easier” and a 1-line #requires -module ActiveDirectory is far easier to write and maintain than, say, and entire function designed specifically to load the ActiveDirectory module.
Wow! That’s the only word I can think of to describe the submissions this time. I’m really impressed with the approaches taken to solve this problem. The only thing that could have been better is quitting when the ActiveDirectory module or the Quest snapin weren’t found. I chalked that up to not having experience with an actual audit where no answer is not acceptable, so I didn’t count against it when evaluating the scripts. But, on this point kudos to the one script that tested for the AD module, then the Quest snapin, and fell back to the ADSI accelerator if neither were found.
Beginner entries
For me, the best entries were those that had the shortest pipelines. Those of you who used Get-Random -Count 20 -InputObject (Get-ADUser…) | Select … | ConvertTo-Html | Out-File had the shortest. And those who used Get-ADUser | Get-Random -Count 20 were a close second.
A couple of entries had something that at first I thought was silly. But, instead, it offers a learning opportunity. Here’s the code fragment: Get-ADUser -Filter {ObjectClass -eq ‘User’}. Paying attention to what the cmdlet does saves a lot of typing, not only here where the filter is redundant, but also when entering other parameters. For example, a similar extra effort occurs when default properties are explicitly listed in a -Properties parameter.
Advanced entries
As mentioned, the best entries were those that fell back to the [ADSI] accelerator when the AD module or the Quest snapin weren’t found. Making this kind of check and fallback is pretty important when responding to audit requests. This reminds me of a case where I actually had to respond to an audit request with the actual last logon date in a domain with mixed W2K3, W2K8, and W2K8R2 domain controllers. The default choice was to use the AD module, but since we had to check each domain controller (there were 72 of them), it turned out to be a real pain determining which method to use on each of them. In the end, we decided to install the Quest tools on the audit server and just avoid the issue.
There were several different methods used to verify the presence of the AD module before trying to load it. Most of them were actually more work that really necessary. The reason for this is that the Import-Module cmdlet does not return an error if the module has already been loaded. Thus, the easiest test would be:
We’re putting together our schedule for 2014 (yes, already), and we’re looking to hold premier-level PowerShell master classes throughout the world. But… we need your help.
If you’ve got a really top-notch training center in your area that might be interested in working with us, contact me. We’ll need the name of someone there - the training manager, the marketing manager, someone like that. We co-market our classes, but rely on a local center to market to their existing customer base as well. These are premium classes, and they do go for a premium price, so the center has to be comfortable marketing that kind of class. We’re not the run-of-the-mill “official curriculum;” my Master Class packs in around eleven days of “normal” training, covering toolmaking, scripting, and advanced topics as well as the introductory-level stuff. _
_
International contacts are fine, and in fact it’s something I’m excited to get going, as international classes also help me set up future PowerShell Forum and PowerShell Saturday events in a country or region.
So think about your area and see if we might be a fit, and if you’ve got a really top-notch training center you can put us in touch with!
Jan offers some perspective on Event 4 at http://blog.powershell.no/2013/05/22/2013-scripting-games-learning-points-from-event-4/
Try adjusting your search terms or browse all content.