February 2019
Intermediate to advanced
626 pages
15h 51m
English
When executing a param block, it is possible to cross-reference parameters. That is, the default value of a parameter can be based on the value of another parameter. This is shown here:
function Get-Substring { param ( [String]$String, [Int]$Start, [Int]$Length = ($String.Length - $Start) ) $String.Substring($Start, $Length)}
The value of the Length parameter will use the default, derived from the first two parameters, unless the user of the function supplies their own value. The order of the parameters is important here: the Start parameter must be created before it can be used in the default value for Length.
Read now
Unlock full access