Appendices
Advanced Parameters

Advanced Parameters

When defining parameters in your PowerShell function, there are a huge number of options you can use to define how your parameters behave. This is a very broad topic, and well beyond the scope of this course, but here are a few of the more common options you might use.

ElementWhat it doesExample
MandatoryRequires the caller to provide a value.[Parameter(Mandatory)] [string]$Name
Data typeConstrains input to a specific .NET type.[int]$Count
PositionAllows unnamed arguments in a specific order.[Parameter(Position = 0)] [string]$Path
ValueFromPipelineAccepts incoming pipeline objects as parameter input.[Parameter(ValueFromPipeline)] [string]$InputObject
ValueFromPipelineByPropertyNameBinds pipeline object properties by matching parameter names.[Parameter(ValueFromPipelineByPropertyName)] [string]$ComputerName
ValidateSetRestricts values to a fixed list of allowed options.[ValidateSet('Dev','Test','Prod')] [string]$Environment
ValidatePatternRequires values to match a regex pattern.[ValidatePattern('^[A-Z]{3}\d{4}$')] [string]$TicketId
ValidateRangeRestricts numeric values to a min and max.[ValidateRange(1,100)] [int]$Percent
AliasAdds alternate names for the same parameter.[Alias('CN')] [string]$ComputerName
ParameterSetNameDefines mutually exclusive parameter combinations.[Parameter(ParameterSetName = 'ById')] [int]$Id