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.

Featured

  • Google Goes Live with Managed Service for Microsoft Active Directory

    Google's Managed Service for Microsoft Active Directory is now a "generally available" service, according to a Thursday Google announcement.

  • Dell Sells RSA Assets for $2 Billion

    Dell's RSA security solutions businesses, including the RSA Conference, were bought by a consortium of companies for about $2 billion, according to Tuesday announcements.

  • How To Get Started as a Windows Insider

    Microsoft's Windows Insider program is invaluable for IT pros who want to test drive new Windows 10 features before the update rolls out to their entire organization. If you haven't already signed up to be an Insider, here's how to do it.

  • Old Fashioned Mics

    Microsoft Preps for RSA Conference with Multiple Security Product Announcements

    Microsoft announced various enterprise security solution product milestones this week in advance of the forthcoming RSA Conference, which will start on Feb. 24.

comments powered by Disqus

Office 365 Watch

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.