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 ...

Get PowerShell Deep Dives now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.