Hello! Quite often in my work I have to use independently written functions and drag pieces of code between different scripts. On Habré there is already a pretty good article about the Reuse of code from Mroff , but there was a need to go a little further, document and somehow describe their functions. As it turned out, the search yielded fairly dry information mainly on the general structure of the function and nothing more. Perseverance was rewarded, and I decided to share the information received. Welcome to the cat, where we will learn to add information to our functions for posterity and colleagues.Function TestPath ([String]$Path) { Return(Test-Path $Path) }  Function TestPath { PARAM ( [PARAMETER(Mandatory=$True,Position=0,HelpMessage = "   ",ParameterSetName='Path')]$Path ) Return(Test-Path $Path) } Mandatory - Accepts two True values are required and False is optional;
HelpMessage - variable help;
ParameterSetName - The name of the variable to which these parameters belong;
Position - The position of the variable when the function is called;
 ((Get-Command TestPath).ParameterSets.Parameters | Where-Object Name -eq Path).HelpMessage  Function WriteToLog { <# .SYNOPSIS        . .DESCRIPTION            PowerShell .EXAMPLE #WriteToLog -Str "           C:\Log\log.txt" -FileName 'C:\Log\log.txt' -Color Red .EXAMPLE #WriteToLog -Str "         (White)    C:\Log\log.txt" -FileName 'C:\Log\log.txt' .PARAMETER Str ,    ( ) .PARAMETER FileName    ( ) .PARAMETER Color      PowerShell (     (White)) #> param ( [PARAMETER(Mandatory=$True,Position=0)][String]$Str, [PARAMETER(Mandatory=$True,Position=1)][String]$FileName, [PARAMETER(Mandatory=$False,Position=2)][String]$Color='White' ) Write-Host $Str -ForegroundColor $Color If ((Test-Path $FileName) -eq $True) { Add-Content -Path $FileName -Value $Str } Else { Set-Content -Path $FileName -Value $Str } } <##> - In this block, the parameters for the PowerShell help are written.
.SYNOPSIS - block for a brief description of the function
.DESCRIPTION - block for full function description
.EXAMPLE - block for an example of using a function, maybe several
.PARAMETR Parameter name - a block for describing a variable, for each variable its own block.
Source: https://habr.com/ru/post/309726/
All Articles