Skip to content

Latest commit

 

History

History
71 lines (36 loc) · 2.38 KB

File metadata and controls

71 lines (36 loc) · 2.38 KB

Best Practices Roundup

Efficient administration is all about following practices which are in line with the philosophy of the tool being used. In this chapter, the best practices are re-iterated so as to ensure that the reader remembers them, along with explanations to why they’re considered best practices.

Using cmdlets

Learn all the best practices pertaining to using PowerShell cmdlets

Using parameter aliases

Learn the best practices in using parameter aliases, and how to declare and use them

Key names for calculated properties

Best practices pertaining to using calculated properties while querying information using one-liners

Using parameters

The best practices with parameters such as usage of named parameters and not using parameter aliases are covered. So is the use of parameter sets when creating functions.

Using comments in scripts and functions

This section talks about striking the right balance when it comes to using comments in scripts.

Naming cmdlets

This section is all about choosing names using approved verbs and balancing readability and length.

Prototyping cmdlets

When creating custom cmdlets, it is important that we add safety switches to system-altering capabilities.

Using regions

Use regions to enable custom code folding and create boundaries around different blocks of code

Error handling

Learn the best practices with respect to error handling

Types of string declarations

The expanding and literal strings

Running scripts without profile

Call scripts without profiles to avoid configuration conflicts

Using objects

This section aims to iterate the fact that PowerShell outputs objects and that’s where its power lies, as opposed to text.

Declaring variables

This section also talks about how to strike a balance between readability and length, but with respect to variables.

Creating parameters

Best practices pertaining to creating and declaring parameters in functions

Writing readable scripts

Best practices in code indentation, braces and flow blocks such as begin, process, end, etc.

Using paths

Sometimes using paths in scripts render them tightly coupled. Also, some usages may render the scripts unusable in some scenarios. This section gives administrators some of the right ways to use paths.

Exporting output

Remember that output from PowerShell is an object, and export the data accordingly