O'Reilly logo

PowerShell Deep Dives by Edited by Jeffery Hicks, Richard Siddaway, Oisín Grehan, and Aleksandar Nikoli

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 9. The 10 PowerShell scripting commandments

James O’Neill

In my view, PowerShell succeeds because it provides a kit of small, general-purpose commands to be linked together to make larger, specific commands. Extending the toolkit is a good thing, and my approach to extending the toolkit can be summarized as “10 commandments” (which I jokingly call cmdments):

1.  Create functions for reuse, scripts for a single task.

2.  Choose names for commands and parameters wisely.

3.  One task, one function: the “DoStuffWith” verb doesn’t exist for a reason.

4.  Build flexibility into parameters.

5.  Ask whether constants are better as defaults for parameters.

6.  Ask “What could I receive?” and “What could I pass on?”

7.  Use ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required