Appendix C. Best practices

 

Best practice is a topic that can, and will, cause arguments, especially among the many passionate members of the PowerShell community. Many people, including myself, have a view of what constitutes best practice. In this appendix, I’ll present some suggestions that distill both my observation of and my experience with PowerShell. These suggestions are based on using PowerShell for over six years, writing and speaking about it, talking to many PowerShell users, and observing the scripts that are available.

Warning

Some the functions in the book do not follow all of these suggestions. This is to reduce the length of the examples (for readability) and to concentrate on the working parts of the functions.

The contents of this appendix are not meant to be prescriptive but to provide a framework for you to adopt or adapt to suit your needs. Be prepared, and know when to step outside of these best practices to solve the problem you have right now. These best practices cover the majority of cases but not necessarily every case.

The first section covers PowerShell in general and the second section extends to WMI.

C.1. PowerShell best practices

This list of tips and suggestions for using PowerShell provides a framework of best practices that will help you produce better scripts in a shorter time. Always remember that your particular situation may cause you to ignore them—getting the job done is the important point.

C.2. WMI best practices