Skip to content

Commit 07e85da

Browse files
authored
Merge pull request #11844 from MicrosoftDocs/main
2/25/2025 PM Publish
2 parents 52b0d41 + 5375296 commit 07e85da

File tree

7 files changed

+227
-149
lines changed

7 files changed

+227
-149
lines changed

reference/5.1/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Explains how to add parameters to advanced functions.
33
Locale: en-US
4-
ms.date: 01/06/2025
4+
ms.date: 02/25/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-5.1&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Functions_Advanced_Parameters
@@ -36,8 +36,8 @@ combination with the `[Alias()]` attribute or any of the parameter validation
3636
attributes.
3737

3838
Parameter names follow the rules for variable names. Parameter names consist of
39-
decimal digits, alphabetic characters, and underscores. For a complete list of
40-
naming rules, see [about_Variables][20].
39+
decimal digits, alphabetical characters, and underscores. For a complete list
40+
of naming rules, see [about_Variables][20].
4141

4242
> [!IMPORTANT]
4343
> It's possible to define a parameter that starts with a decimal digit.
@@ -189,24 +189,23 @@ has a **false** value.
189189
For example, the **Recurse** parameter of `Get-ChildItem` is a switch
190190
parameter.
191191

192-
To create a switch parameter in a function, specify the `switch` type in the
193-
parameter definition.
194-
195-
For example, your function may have an option to output data as a byte array:
192+
To create a switch parameter in a function, specify the `[switch]` type in the
193+
parameter definition. The following example shows the definition of a switch
194+
parameter that could be used to provide an option to output data as a byte
195+
array:
196196

197197
```powershell
198198
param([switch]$AsByteArray)
199199
```
200200

201-
Switch parameters are easy to use and are preferred over Boolean parameters,
202-
which have a less natural syntax for PowerShell.
201+
Switch parameters are easy to use and are preferred over Boolean parameters
202+
that have a less natural syntax for PowerShell.
203203

204-
For example, to use a switch parameter, the user types the parameter in the
205-
command.
204+
To use a switch parameter, include the parameter in the command. For example:
206205

207206
`-IncludeAll`
208207

209-
To use a Boolean parameter, the user types the parameter and a Boolean value.
208+
To use a Boolean parameter, you must provide the parameter and a Boolean value.
210209

211210
`-IncludeAll $true`
212211

@@ -217,29 +216,37 @@ value is required.
217216

218217
### Switch parameter design considerations
219218

220-
- Switch parameters shouldn't be given default values. They should always
219+
- Don't set a default value for a switch parameter. Switch parameter always
221220
default to false.
222-
- Switch parameters are excluded from positional parameters by default. Even
223-
when other parameters are implicitly positional, switch parameters aren't.
224-
You _can_ override that in the Parameter attribute, but it will confuse
225-
users.
226-
- Switch parameters should be designed so that setting them moves a command
227-
from its default behavior to a less common or more complicated mode. The
228-
simplest behavior of a command should be the default behavior that doesn't
229-
require the use of switch parameters.
230-
- Switch parameters shouldn't be mandatory. The only case where it's necessary
231-
to make a switch parameter mandatory is when it's needed to differentiate a
221+
- Don't make switch parameters positional. By default, switch parameters are
222+
excluded from positional parameters. You _can_ override that in the
223+
**Parameter** attribute, but it can confuse users.
224+
- Design switch parameters so that using parameter changes the default behavior
225+
of the command to a less common or more complicated mode. The simplest
226+
behavior of a command should be the default behavior that doesn't require the
227+
use of switch parameters.
228+
- Don't make switch parameters mandatory. The only case where it's helpful to
229+
make a switch parameter mandatory is when it's needed to differentiate a
232230
parameter set.
233-
- Explicitly setting a switch from a boolean can be done with
234-
`-MySwitch:$boolValue` and in splatting with
235-
`$params = @{ MySwitch = $boolValue }`.
236-
- Switch parameters are of type `SwitchParameter`, which implicitly converts to
237-
Boolean. The parameter variable can be used directly in a conditional
238-
expression. For example:
231+
- Use the switch parameter variable directly in a conditional expression. The
232+
`SwitchParameter` type implicitly converts to Boolean. For example:
233+
234+
```powershell
235+
if ($MySwitch) { ... }
236+
```
237+
238+
- Always base the behavior controlled by the switch on the value of the switch,
239+
not the presence of the parameter. There are several ways to test for the
240+
presence of a switch parameters:
239241

240-
`if ($MySwitch) { ... }`
242+
- `$PSBoundParameters` contains the switch parameter name as a key
243+
- `$MyInvocation.BoundParameters` contains the switch parameter name as a key
244+
- `$PSCmdlet.ParameterSetName` when the switch defines a unique parameter set
241245

242-
There's no need to write `if ($MySwitch.IsPresent) { ... }`
246+
For example, it's possible to provide an explicit value for the switch using
247+
`-MySwitch:$false` or splatting. If you only test for the presence of the
248+
parameter, the command behaves as if the switch value is `$true` instead of
249+
`$false`.
243250

244251
## Dynamic parameters
245252

@@ -594,7 +601,7 @@ function Test-Remainder {
594601
"${i}: $($Remaining[$i])"
595602
}
596603
}
597-
Test-Remainder first one,two
604+
Test-Remainder first one, two
598605
```
599606

600607
```Output

reference/5.1/Microsoft.PowerShell.Management/Add-Computer.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,11 @@ Accept wildcard characters: False
454454
### -Server
455455

456456
Specifies the name of a domain controller that adds the computer to the domain. Enter the name in
457-
DomainName\ComputerName format. By default, no domain controller is specified.
457+
FQDN format. By default, no domain controller is specified.
458+
459+
Beginning in August 2024, security hardening for domain join requires that you use the FQDN of the
460+
domain controller. For example: `DC1.contoso.com`. For more information, see
461+
[NetJoin Domain Join Hardning Changes](https://support.microsoft.com/topic/kb5020276-netjoin-domain-join-hardening-changes-2b65a0f3-1f4c-42ef-ac0f-1caaf421baf8).
458462

459463
```yaml
460464
Type: System.String

reference/7.4/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Explains how to add parameters to advanced functions.
33
Locale: en-US
4-
ms.date: 01/06/2025
4+
ms.date: 02/25/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-7.4&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Functions_Advanced_Parameters
@@ -36,8 +36,8 @@ combination with the `[Alias()]` attribute or any of the parameter validation
3636
attributes.
3737

3838
Parameter names follow the rules for variable names. Parameter names consist of
39-
decimal digits, alphabetic characters, and underscores. For a complete list of
40-
naming rules, see [about_Variables][20].
39+
decimal digits, alphabetical characters, and underscores. For a complete list
40+
of naming rules, see [about_Variables][20].
4141

4242
> [!IMPORTANT]
4343
> It's possible to define a parameter that starts with a decimal digit.
@@ -184,24 +184,23 @@ has a **false** value.
184184
For example, the **Recurse** parameter of `Get-ChildItem` is a switch
185185
parameter.
186186

187-
To create a switch parameter in a function, specify the `switch` type in the
188-
parameter definition.
189-
190-
For example, your function may have an option to output data as a byte array:
187+
To create a switch parameter in a function, specify the `[switch]` type in the
188+
parameter definition. The following example shows the definition of a switch
189+
parameter that could be used to provide an option to output data as a byte
190+
array:
191191

192192
```powershell
193193
param([switch]$AsByteArray)
194194
```
195195

196-
Switch parameters are easy to use and are preferred over Boolean parameters,
197-
which have a less natural syntax for PowerShell.
196+
Switch parameters are easy to use and are preferred over Boolean parameters
197+
that have a less natural syntax for PowerShell.
198198

199-
For example, to use a switch parameter, the user types the parameter in the
200-
command.
199+
To use a switch parameter, include the parameter in the command. For example:
201200

202201
`-IncludeAll`
203202

204-
To use a Boolean parameter, the user types the parameter and a Boolean value.
203+
To use a Boolean parameter, you must provide the parameter and a Boolean value.
205204

206205
`-IncludeAll $true`
207206

@@ -212,29 +211,37 @@ value is required.
212211

213212
### Switch parameter design considerations
214213

215-
- Switch parameters shouldn't be given default values. They should always
214+
- Don't set a default value for a switch parameter. Switch parameter always
216215
default to false.
217-
- Switch parameters are excluded from positional parameters by default. Even
218-
when other parameters are implicitly positional, switch parameters aren't.
219-
You _can_ override that in the Parameter attribute, but it will confuse
220-
users.
221-
- Switch parameters should be designed so that setting them moves a command
222-
from its default behavior to a less common or more complicated mode. The
223-
simplest behavior of a command should be the default behavior that doesn't
224-
require the use of switch parameters.
225-
- Switch parameters shouldn't be mandatory. The only case where it's necessary
226-
to make a switch parameter mandatory is when it's needed to differentiate a
216+
- Don't make switch parameters positional. By default, switch parameters are
217+
excluded from positional parameters. You _can_ override that in the
218+
**Parameter** attribute, but it can confuse users.
219+
- Design switch parameters so that using parameter changes the default behavior
220+
of the command to a less common or more complicated mode. The simplest
221+
behavior of a command should be the default behavior that doesn't require the
222+
use of switch parameters.
223+
- Don't make switch parameters mandatory. The only case where it's helpful to
224+
make a switch parameter mandatory is when it's needed to differentiate a
227225
parameter set.
228-
- Explicitly setting a switch from a boolean can be done with
229-
`-MySwitch:$boolValue` and in splatting with
230-
`$params = @{ MySwitch = $boolValue }`.
231-
- Switch parameters are of type `SwitchParameter`, which implicitly converts to
232-
Boolean. The parameter variable can be used directly in a conditional
233-
expression. For example:
226+
- Use the switch parameter variable directly in a conditional expression. The
227+
`SwitchParameter` type implicitly converts to Boolean. For example:
228+
229+
```powershell
230+
if ($MySwitch) { ... }
231+
```
232+
233+
- Always base the behavior controlled by the switch on the value of the switch,
234+
not the presence of the parameter. There are several ways to test for the
235+
presence of a switch parameters:
234236

235-
`if ($MySwitch) { ... }`
237+
- `$PSBoundParameters` contains the switch parameter name as a key
238+
- `$MyInvocation.BoundParameters` contains the switch parameter name as a key
239+
- `$PSCmdlet.ParameterSetName` when the switch defines a unique parameter set
236240

237-
There's no need to write `if ($MySwitch.IsPresent) { ... }`
241+
For example, it's possible to provide an explicit value for the switch using
242+
`-MySwitch:$false` or splatting. If you only test for the presence of the
243+
parameter, the command behaves as if the switch value is `$true` instead of
244+
`$false`.
238245

239246
## Dynamic parameters
240247

reference/7.5/Microsoft.PowerShell.Core/About/about_Functions_Advanced_Parameters.md

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Explains how to add parameters to advanced functions.
33
Locale: en-US
4-
ms.date: 01/06/2025
4+
ms.date: 02/25/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-7.5&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Functions_Advanced_Parameters
@@ -36,8 +36,8 @@ combination with the `[Alias()]` attribute or any of the parameter validation
3636
attributes.
3737

3838
Parameter names follow the rules for variable names. Parameter names consist of
39-
decimal digits, alphabetic characters, and underscores. For a complete list of
40-
naming rules, see [about_Variables][20].
39+
decimal digits, alphabetical characters, and underscores. For a complete list
40+
of naming rules, see [about_Variables][20].
4141

4242
> [!IMPORTANT]
4343
> It's possible to define a parameter that starts with a decimal digit.
@@ -184,24 +184,23 @@ has a **false** value.
184184
For example, the **Recurse** parameter of `Get-ChildItem` is a switch
185185
parameter.
186186

187-
To create a switch parameter in a function, specify the `switch` type in the
188-
parameter definition.
189-
190-
For example, your function may have an option to output data as a byte array:
187+
To create a switch parameter in a function, specify the `[switch]` type in the
188+
parameter definition. The following example shows the definition of a switch
189+
parameter that could be used to provide an option to output data as a byte
190+
array:
191191

192192
```powershell
193193
param([switch]$AsByteArray)
194194
```
195195

196-
Switch parameters are easy to use and are preferred over Boolean parameters,
197-
which have a less natural syntax for PowerShell.
196+
Switch parameters are easy to use and are preferred over Boolean parameters
197+
that have a less natural syntax for PowerShell.
198198

199-
For example, to use a switch parameter, the user types the parameter in the
200-
command.
199+
To use a switch parameter, include the parameter in the command. For example:
201200

202201
`-IncludeAll`
203202

204-
To use a Boolean parameter, the user types the parameter and a Boolean value.
203+
To use a Boolean parameter, you must provide the parameter and a Boolean value.
205204

206205
`-IncludeAll $true`
207206

@@ -212,29 +211,37 @@ value is required.
212211

213212
### Switch parameter design considerations
214213

215-
- Switch parameters shouldn't be given default values. They should always
214+
- Don't set a default value for a switch parameter. Switch parameter always
216215
default to false.
217-
- Switch parameters are excluded from positional parameters by default. Even
218-
when other parameters are implicitly positional, switch parameters aren't.
219-
You _can_ override that in the Parameter attribute, but it will confuse
220-
users.
221-
- Switch parameters should be designed so that setting them moves a command
222-
from its default behavior to a less common or more complicated mode. The
223-
simplest behavior of a command should be the default behavior that doesn't
224-
require the use of switch parameters.
225-
- Switch parameters shouldn't be mandatory. The only case where it's necessary
226-
to make a switch parameter mandatory is when it's needed to differentiate a
216+
- Don't make switch parameters positional. By default, switch parameters are
217+
excluded from positional parameters. You _can_ override that in the
218+
**Parameter** attribute, but it can confuse users.
219+
- Design switch parameters so that using parameter changes the default behavior
220+
of the command to a less common or more complicated mode. The simplest
221+
behavior of a command should be the default behavior that doesn't require the
222+
use of switch parameters.
223+
- Don't make switch parameters mandatory. The only case where it's helpful to
224+
make a switch parameter mandatory is when it's needed to differentiate a
227225
parameter set.
228-
- Explicitly setting a switch from a boolean can be done with
229-
`-MySwitch:$boolValue` and in splatting with
230-
`$params = @{ MySwitch = $boolValue }`.
231-
- Switch parameters are of type `SwitchParameter`, which implicitly converts to
232-
Boolean. The parameter variable can be used directly in a conditional
233-
expression. For example:
226+
- Use the switch parameter variable directly in a conditional expression. The
227+
`SwitchParameter` type implicitly converts to Boolean. For example:
228+
229+
```powershell
230+
if ($MySwitch) { ... }
231+
```
232+
233+
- Always base the behavior controlled by the switch on the value of the switch,
234+
not the presence of the parameter. There are several ways to test for the
235+
presence of a switch parameters:
234236

235-
`if ($MySwitch) { ... }`
237+
- `$PSBoundParameters` contains the switch parameter name as a key
238+
- `$MyInvocation.BoundParameters` contains the switch parameter name as a key
239+
- `$PSCmdlet.ParameterSetName` when the switch defines a unique parameter set
236240

237-
There's no need to write `if ($MySwitch.IsPresent) { ... }`
241+
For example, it's possible to provide an explicit value for the switch using
242+
`-MySwitch:$false` or splatting. If you only test for the presence of the
243+
parameter, the command behaves as if the switch value is `$true` instead of
244+
`$false`.
238245

239246
## Dynamic parameters
240247

0 commit comments

Comments
 (0)