General Script Readability

There are several things you can do to ensure your scripts are as readable as possible. In this section we will look at some of the more important items.

  • When creating an alias, include the -description parameter, and use it when searching for your personal aliases. An example of this is shown here:

    Get-Alias |
    where-object { $_.description -match 'mred' } |
    Format-Table -Property "   ",name, definition -autosize `
                 -hideTableHeaders
  • Scripts should accept -help and print a help text. You can implement -help as a named parameter:

    Param($help)
  • Alternatively, you can implement the -help parameter as a switch statement. The switch is easiest to implement:

    Param([switch]$help)
  • All procedures should begin with a brief comment describing ...

Get Windows PowerShell™ Scripting Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.