In-Depth
Q&A: Why You're Writing Your PowerShell Functions Wrong!
Don Jones, TechMentor presenter and cochair, discusses some of his observations on how people are using PowerShell, and how they could do a better job.
If you ever need to know more about PowerShell, if you ever had any questions about building functions or scripts, you need to hear from Don Jones. Over the years, Jones has spoken about written countless articles, authored and coauthored books about how to get the most value out of "the shell."
We spoke with Don about PowerShell about his forthcoming session at TechMentor as part of Live! 360 and some of the things he believes PowerShell users could be doing differently to make their lives easier.
What is the number one mistake you see even experienced PowerShell users making?
People tend to take an old-school programming or scripting approach to PowerShell, and that's just not necessary. They end up working a lot harder than they need. They'll accumulate objects, or output text, neither of which aligns with how the shell is designed.
What one thing do you wish all PowerShell users learned at the beginning?
People need to learn how the pipeline actually works in PowerShell. I know people think they know, but they really don't.
When it comes to modularizing functions, what is your number one tip?
Make your functions do one thing. Query something, format something, convert something, whatever the task at hand -- but make your function do only that. Functions shouldn't do multiple things. Then they become tied to a purpose, and they're less reusable.
What error and debugging mistakes do you see the most?
People don't understand that bugs are almost always the result of a property or variable not containing what you thought they did. Debugging is all about validating things, and having an expectation for what those should be and how they should work.
What mistakes do you see people make that cost them the most time?
Most eager PowerShell users over-build their functions or scripts to do too many things. You'd get more reuse from old code if your code was more granularly and tightly scoped.
Find out more about Live! 360 2016 in Orlando here.
About the Author
Lafe Low is the editorial liaison for ECG Events.