Skip to content

Standards

Andrew Davidson edited this page Dec 27, 2020 · 14 revisions

Standards

Modules should

  • have one or more functions in them
  • have a valid accompanying module manifest

Module manifests should

  • have all functions from the module exported

Module functions and script files should

  • have help text detailing the function of the code at the top (For functions this must be inside the function)
  • have a [CmdletBinding()] property
  • have an [OutputType()] property that must contain one or more OutputTypes
  • have a param block
  • have any parameters in the param block detailed with a .PARAMETER in the help text
  • have variable types for all parameters
  • have the keyword function and the name of the function on the same line
  • use PowerShell approved verbs and singular nouns. For approved verbs see (for v5.1) or (for v7.1)

An example of a valid functions layout:

function Get-File {
    <#
        .SYNOPSIS
        Get the content of the file

        .DESCRIPTION
        Get and return the content of the passed PowerShell file

        .PARAMETER Path
        A string containing PowerShell filename

        .EXAMPLE
        Get-File -Path $File

    #>
    [CmdletBinding()]
    [OutputType([System.String[]])]
    param (
        [parameter(Mandatory = $true)]
        [string]$Path
    )

    $fileContent = Get-Content -Path $Path -Raw

    return $fileContent

}
Clone this wiki locally