11---
22description : Explains how to add parameters to advanced functions.
33Locale : en-US
4- ms.date : 03/10 /2026
4+ ms.date : 04/08 /2026
55online version : https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-5.1&WT.mc_id=ps-gethelp
66schema : 2.0.0
77title : about_Functions_Advanced_Parameters
@@ -178,68 +178,68 @@ param(
178178)
179179```
180180
181- ## Switch parameters
181+ ## ` [switch] ` parameters
182182
183- Switch parameters are parameters that take no parameter value. Instead, they
184- convey a Boolean true-or-false value through their presence or absence, so that
185- when a switch parameter is present it has a ** true** value and when absent it
186- has a ** false** value.
183+ ` [switch] ` parameters are parameters that take no parameter value. Instead,
184+ they convey a Boolean true-or-false value through their presence or absence, so
185+ that when a ` [ switch] ` parameter is present it has a ** true** value and when
186+ absent it has a ** false** value.
187187
188- For example, the ** Recurse** parameter of ` Get-ChildItem ` is a switch
188+ For example, the ** Recurse** parameter of ` Get-ChildItem ` is a ` [ switch] `
189189parameter.
190190
191- To create a switch parameter in a function, specify the ` [switch] ` type in the
192- parameter definition. The following example shows the definition of a switch
193- parameter that could be used to provide an option to output data as a byte
194- array:
191+ The following example shows the definition of a ` [switch] ` parameter that could
192+ be used to provide an option to output data as a byte array:
195193
196194``` powershell
197195param([switch]$AsByteArray)
198196```
199197
200- Switch parameters are easy to use and are preferred over Boolean parameters
198+ ` [switch] ` parameters are easy to use and are preferred over Boolean parameters
201199that have a less natural syntax for PowerShell.
202200
203- To use a switch parameter, include the parameter in the command. For example:
201+ To use a ` [switch] ` parameter, include the parameter in the command. For
202+ example:
204203
205204` -IncludeAll `
206205
207206To use a Boolean parameter, you must provide the parameter and a Boolean value.
208207
209208` -IncludeAll $true `
210209
211- When creating switch parameters, choose the parameter name carefully. Be sure
212- that the parameter name communicates the effect of the parameter to the user.
213- Avoid ambiguous terms, such as ** Filter** or ** Maximum** that might imply a
214- value is required.
210+ When creating ` [ switch] ` parameters, choose the parameter name carefully. Be
211+ sure that the parameter name communicates the effect of the parameter to the
212+ user. Avoid ambiguous terms, such as ** Filter** or ** Maximum** that might imply
213+ a value is required.
215214
216- ### Switch parameter design considerations
215+ ### ` [switch] ` parameter design considerations
217216
218- - Don't set a default value for a switch parameter. Switch parameter always
219- default to false.
220- - Don't make switch parameters positional. By default, switch parameters are
221- excluded from positional parameters. You _ can_ override that in the
222- ** Parameter** attribute, but it can confuse users.
223- - Design switch parameters so that using parameter changes the default behavior
217+ - Don't set a default value for a ` [ switch] ` parameter. ` [switch] ` parameters
218+ always default to false.
219+ - Don't make ` [ switch] ` parameters positional. By default, ` [ switch] `
220+ parameters are excluded from positional parameters. You _ can_ override that
221+ in the ** Parameter** attribute, but it can confuse users.
222+ - Design ` [ switch] ` parameters so that using them changes the default behavior
224223 of the command to a less common or more complicated mode. The simplest
225224 behavior of a command should be the default behavior that doesn't require the
226- use of switch parameters.
227- - Don't make switch parameters mandatory. The only case where it's helpful to
228- make a switch parameter mandatory is when it's needed to differentiate a
229- parameter set.
230- - Use the switch parameter variable directly in a conditional expression. The
231- ` SwitchParameter ` type implicitly converts to Boolean. For example:
225+ use of ` [ switch] ` parameters.
226+ - Don't make ` [ switch] ` parameters mandatory. The only case where it's helpful
227+ to make a ` [ switch] ` parameter mandatory is when it's needed to differentiate
228+ a parameter set.
229+ - Use the ` [ switch] ` parameter variable directly in a conditional expression.
230+ The ` SwitchParameter ` type implicitly converts to Boolean. For example:
232231
233232 ``` powershell
234233 if ($MySwitch) { ... }
235234 ```
236235
237- - Always base the behavior controlled by the switch on the value of the switch,
238- not the presence of the parameter. There are several ways to test for the
239- presence of a switch parameters:
236+ - Always base the behavior controlled by the ` [ switch] ` parameter on the
237+ _ value _ of the parameter, not its _ presence _ . There are several ways to test
238+ for the presence of a ` [ switch] ` parameters:
240239
241- - ` $PSBoundParameters ` contains the switch parameter name as a key
242- - ` $MyInvocation.BoundParameters ` contains the switch parameter name as a key
240+ - ` $PSBoundParameters ` contains the ` [switch] ` parameter name as a key
241+ - ` $MyInvocation.BoundParameters ` contains the ` [switch] ` parameter name as a
242+ key
243243 - ` $PSCmdlet.ParameterSetName ` when the switch defines a unique parameter set
244244
245245 For example, it's possible to provide an explicit value for the switch using
@@ -773,7 +773,7 @@ Use the **System.Obsolete** attribute to mark parameters that are no longer
773773supported. This can be useful when you want to remove a parameter from a
774774function but you don't want to break existing scripts that use the function.
775775
776- For example, consider a function that has a ** NoTypeInformation** switch
776+ For example, consider a function that has a ** NoTypeInformation** ` [ switch] `
777777parameter that controls whether type information is included in the output. You
778778want to make that behavior the default and remove the parameter from the
779779function. However, you don't want to break existing scripts that use the
@@ -783,7 +783,7 @@ explains the change.
783783``` powershell
784784param(
785785 [System.Obsolete("The NoTypeInformation parameter is obsolete.")]
786- [SwitchParameter ]$NoTypeInformation
786+ [switch ]$NoTypeInformation
787787)
788788```
789789
0 commit comments