Jeffrey Hicks has written a great article for PSBlogWeek on how you can implement -WhatIf and -Confirm in your advanced functions, providing another level of assurance when testing commands. When I write tools for other team members, I always try to include the -WhatIf parameter, so they can get a level of comfort prior to issuing a command.
Check out this great post by Mike Robbins, part 2 of #PSBlogWeek, covering basic parameter validation in PowerShell.
You don’t think much about parameter validation while writing scripts for yourself, but they’ll save you a lot of headaches once you start creating tools for other people to use. Properly used, parameter validation can make your script almost self-documenting for a new user, prompting them for the needed information.
If you missed it, be sure to check out Francis-Xavier Cat’s part 1 of #PSBlogWeek, discussing standard and advanced functions (and why you should be writing advanced functions).
Francis-Xavier Cat kicks off #PSBlogWeek discussing standard and advanced functions and why you should be writing advanced functions.
Honestly, it’s so easy and gets you so much, there’s no reason not to write advanced functions.
We’ll have some great content coming soon, but the most common question I get with PowerShell is, “What book do you recommend?” So, until I get some content up, the books I recommend:
Learn Windows PowerShell 3 in a Month of Lunches
If you’re new to Windows PowerShell, Learn Windows PowerShell 3 in a Month of Lunches is a great place to start. Each chapter is designed to be completed during a lunch break, sitting at your desk working through the chapters. The scripts you’ll write build on themselves each chapter, refining and improving as you go. A great introduction to the language.
PowerShell in Depth: An administrator’s guide
PowerShell in Depth: An administrator’s guide is a great book, covering the basics and way beyond. I find it indispensable as a reference tool, dog-earing my paper copy and searching my Kindle version quite often. Covers creating your own objects, advanced functions, working with .NET, working with databases, even building a GUI.
Learn PowerShell Toolmaking in a Month of Lunches
Learn PowerShell Toolmaking in a Month of Lunches is my favorite of the bunch. If you’re familiar with PowerShell and you regularly write scripts for other teams / administrators, you need this book. I’m obsessed with advanced functions, [CmdletBinding()], comment-based help, and write-output; so this is right up my alley. They cover proper tool design, ensuring your tool can work with a variety of inputs, as well as providing proper output that other commands can utilize. These techniques will take your scripting and reusable functions to a new level.