Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes how to define and use parameter sets in advanced functions.
Locale: en-US
ms.date: 06/05/2023
ms.date: 10/02/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_parameter_sets?view=powershell-5.1&WT.mc_id=ps-gethelp
title: about Parameter Sets
---
Expand Down Expand Up @@ -46,7 +46,7 @@ of the **CmdletBinding** attribute specifies the default parameter set.
PowerShell uses the default parameter set when it can't determine the parameter
set to use based on the information provided to the command. For more
information about the **CmdletBinding** attribute, see
[about_functions_cmdletbindingattribute](about_functions_cmdletbindingattribute.md).
[about_Functions_CmdletBindingAttribute][01].

## Declaring parameter sets

Expand Down Expand Up @@ -79,21 +79,13 @@ defined:
function Measure-Lines {
[CmdletBinding(DefaultParameterSetName = 'Path')]
param (
[Parameter(Mandatory = $true,
ParameterSetName = 'Path',
HelpMessage = 'Enter one or more filenames',
Position = 0)]
[Parameter(Mandatory = $true,
ParameterSetName = 'PathAll',
Position = 0)]
[Parameter(Mandatory, ParameterSetName = 'Path', Position = 0)]
[Parameter(Mandatory, ParameterSetName = 'PathAll', Position = 0)]
[string[]]$Path,

[Parameter(Mandatory = $true, ParameterSetName = 'LiteralPathAll')]
[Parameter(Mandatory = $true,
ParameterSetName = 'LiteralPath',
HelpMessage = 'Enter a single filename',
ValueFromPipeline = $true)]
[string]$LiteralPath,
[Parameter(Mandatory, ParameterSetName = 'LiteralPathAll', ValueFromPipeline)]
[Parameter(Mandatory, ParameterSetName = 'LiteralPath', ValueFromPipeline)]
[string[]]$LiteralPath,

[Parameter(ParameterSetName = 'Path')]
[Parameter(ParameterSetName = 'LiteralPath')]
Expand All @@ -107,8 +99,8 @@ function Measure-Lines {
[Parameter(ParameterSetName = 'LiteralPath')]
[switch]$Characters,

[Parameter(Mandatory = $true, ParameterSetName = 'PathAll')]
[Parameter(Mandatory = $true, ParameterSetName = 'LiteralPathAll')]
[Parameter(Mandatory, ParameterSetName = 'PathAll')]
[Parameter(Mandatory, ParameterSetName = 'LiteralPathAll')]
[switch]$All,

[Parameter(ParameterSetName = 'Path')]
Expand All @@ -121,17 +113,16 @@ function Measure-Lines {
$Lines = $Words = $Characters = $true
}
elseif (($Words -eq $false) -and ($Characters -eq $false)) {
$Lines = $true
$Lines = $true
}

}
process {
if ($Path) {
$Files = Get-ChildItem -Path $Path -Recurse:$Recurse -File
}
else {
$Files = Get-ChildItem -LiteralPath $LiteralPath -File
}
}
process {
foreach ($file in $Files) {
$result = [ordered]@{ }
$result.Add('File', $file.fullname)
Expand Down Expand Up @@ -166,7 +157,7 @@ with the `LiteralPath` and `LiteralPathAll` parameter sets. Even though the
the **Path** and **LiteralPath** parameters differentiate them.

Use `Get-Command -Syntax` shows you the syntax of each parameter set. However
it does not show the name of the parameter set. The following example shows
it doesn't show the name of the parameter set. The following example shows
which parameters can be used in each parameter set.

```powershell
Expand All @@ -180,13 +171,13 @@ ParameterSetName Parameters
---------------- ----------
Path [-Path] <string[]> [-Lines] [-Words] [-Characters] [-Recurse] [<CommonParameters>]
PathAll [-Path] <string[]> -All [-Recurse] [<CommonParameters>]
LiteralPath -LiteralPath <string> [-Lines] [-Words] [-Characters] [<CommonParameters>]
LiteralPathAll -LiteralPath <string> -All [<CommonParameters>]
LiteralPath -LiteralPath <string[]> [-Lines] [-Words] [-Characters] [<CommonParameters>]
LiteralPathAll -LiteralPath <string[]> -All [<CommonParameters>]
```

### Parameter sets in action

In this example, we are using the `PathAll` parameter set.
The example uses the `PathAll` parameter set.

```powershell
Measure-Lines test* -All
Expand All @@ -210,7 +201,7 @@ Get-ChildItem -Path $PSHOME -LiteralPath $PSHOME
```

```Output
Get-ChildItem : Parameter set cannot be resolved using the specified named parameters.
Get-ChildItem : Parameter set can't be resolved using the specified named parameters.
At line:1 char:1
+ Get-ChildItem -Path $PSHOME -LiteralPath $PSHOME
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -222,3 +213,6 @@ The **Path** and **LiteralPath** parameters are unique to different parameter
sets of the `Get-ChildItem` cmdlet. When the parameters are run together in the
same cmdlet, an error is thrown. Only one parameter set can be used per cmdlet
call at a time.

<!-- link references -->
[01]: about_functions_cmdletbindingattribute.md
31 changes: 14 additions & 17 deletions reference/5.1/PSReadLine/Set-PSReadLineKeyHandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
external help file: Microsoft.PowerShell.PSReadLine2.dll-Help.xml
Locale: en-US
Module Name: PSReadline
ms.date: 12/13/2022
ms.date: 10/02/2023
online version: https://learn.microsoft.com/powershell/module/psreadline/set-psreadlinekeyhandler?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: Set-PSReadLineKeyHandler
Expand Down Expand Up @@ -32,7 +32,7 @@ Set-PSReadLineKeyHandler [-Chord] <String[]> [-ViMode <ViMode>] [-Function] <Str
## DESCRIPTION

The `Set-PSReadLineKeyHandler` cmdlet customizes the result when a key or sequence of keys is
pressed. With user-defined key bindings, you can do almost anything that is possible from within a
pressed. With user-defined key bindings, you can do almost anything that's possible from within a
PowerShell script.

## EXAMPLES
Expand All @@ -48,11 +48,11 @@ Set-PSReadLineKeyHandler -Chord UpArrow -Function HistorySearchBackward

### Example 2: Bind a key to a script block

This example shows how a single key can be used to run a command. The command binds the key `Ctrl+B`
This example shows how a single key can be used to run a command. The command binds the key `Ctrl+b`
to a script block that clears the line, inserts the word "build", and then accepts the line.

```powershell
Set-PSReadLineKeyHandler -Chord Ctrl+B -ScriptBlock {
Set-PSReadLineKeyHandler -Chord Ctrl+b -ScriptBlock {
[Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
[Microsoft.PowerShell.PSConsoleReadLine]::Insert('build')
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
Expand Down Expand Up @@ -81,14 +81,12 @@ Accept wildcard characters: False
### -Chord

The key or sequence of keys to be bound to a function or script block. Use a single string to
specify a single binding. If the binding is a sequence of keys, separate the keys by a comma, as in
the following example:
specify a single binding. If the binding is a sequence of keys, separate the keys by a comma. For
example: `Ctrl+x,Ctrl+l`

`Ctrl+X,Ctrl+L`

> [!NOTE]
> As of PSReadLine 2.0.0, the **Chord** parameter is **case-sensitive**. Meaning,
> <kbd>Ctrl</kbd>+<kbd>X</kbd> and <kbd>Ctrl</kbd>+<kbd>x</kbd> create different bindings.
Letter key references are defined using lowercase letters. If you want to define a chord that uses
an uppercase letter, the chord must include the **Shift** key. For example, `Ctrl+Shift+x` and
`Ctrl+x` create different bindings.

This parameter accepts an array of strings. Each string is a separate binding, not a sequence of
keys for a single binding.
Expand All @@ -107,7 +105,7 @@ Accept wildcard characters: False

### -Description

Specifies a more detailed description of the key binding that is visible in the output of the
Specifies a more detailed description of the key binding that's visible in the output of the
`Get-PSReadLineKeyHandler` cmdlet.

```yaml
Expand All @@ -125,7 +123,7 @@ Accept wildcard characters: False
### -Function

Specifies the name of an existing key handler provided by PSReadLine. This parameter lets you rebind
existing key bindings, or bind a handler that is currently unbound.
existing key bindings, or bind a handler that's currently unbound.

```yaml
Type: System.String
Expand Down Expand Up @@ -180,10 +178,9 @@ Accept wildcard characters: False

### CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction,
-ErrorVariable, -InformationAction, -InformationVariable, -OutVariable,
-OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose,
-WarningAction, and -WarningVariable. For more information, see
[about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS
Expand Down
12 changes: 8 additions & 4 deletions reference/5.1/PSReadLine/Set-PSReadLineOption.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
external help file: Microsoft.PowerShell.PSReadLine2.dll-Help.xml
Locale: en-US
Module Name: PSReadLine
ms.date: 08/22/2023
ms.date: 10/02/2023
online version: https://learn.microsoft.com/powershell/module/psreadline/set-psreadlineoption?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: Set-PSReadLineOption
Expand Down Expand Up @@ -540,10 +540,14 @@ Specifies how **PSReadLine** saves history.

Valid values are as follows:

- **SaveIncrementally**: Save history after each command is executed and share across multiple
- `SaveIncrementally`: Save history after each command is executed and share across multiple
instances of PowerShell.
- **SaveAtExit**: Append history file when PowerShell exits.
- **SaveNothing**: Don't use a history file.
- `SaveAtExit`: Append history file when PowerShell exits.
- `SaveNothing`: Don't use a history file.

> [!NOTE]
> If you set **HistorySaveStyle** to `SaveNothing` and then set it to `SaveIncrementally` later in
> the same session, PSReadLine saves all the commands previously run in the session.

```yaml
Type: Microsoft.PowerShell.HistorySaveStyle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes how to define and use parameter sets in advanced functions.
Locale: en-US
ms.date: 06/05/2023
ms.date: 10/02/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_parameter_sets?view=powershell-7.2&WT.mc_id=ps-gethelp
title: about Parameter Sets
---
Expand Down Expand Up @@ -46,7 +46,7 @@ of the **CmdletBinding** attribute specifies the default parameter set.
PowerShell uses the default parameter set when it can't determine the parameter
set to use based on the information provided to the command. For more
information about the **CmdletBinding** attribute, see
[about_functions_cmdletbindingattribute](about_functions_cmdletbindingattribute.md).
[about_Functions_CmdletBindingAttribute][01].

## Declaring parameter sets

Expand Down Expand Up @@ -79,21 +79,13 @@ defined:
function Measure-Lines {
[CmdletBinding(DefaultParameterSetName = 'Path')]
param (
[Parameter(Mandatory = $true,
ParameterSetName = 'Path',
HelpMessage = 'Enter one or more filenames',
Position = 0)]
[Parameter(Mandatory = $true,
ParameterSetName = 'PathAll',
Position = 0)]
[Parameter(Mandatory, ParameterSetName = 'Path', Position = 0)]
[Parameter(Mandatory, ParameterSetName = 'PathAll', Position = 0)]
[string[]]$Path,

[Parameter(Mandatory = $true, ParameterSetName = 'LiteralPathAll')]
[Parameter(Mandatory = $true,
ParameterSetName = 'LiteralPath',
HelpMessage = 'Enter a single filename',
ValueFromPipeline = $true)]
[string]$LiteralPath,
[Parameter(Mandatory, ParameterSetName = 'LiteralPathAll', ValueFromPipeline)]
[Parameter(Mandatory, ParameterSetName = 'LiteralPath', ValueFromPipeline)]
[string[]]$LiteralPath,

[Parameter(ParameterSetName = 'Path')]
[Parameter(ParameterSetName = 'LiteralPath')]
Expand All @@ -107,8 +99,8 @@ function Measure-Lines {
[Parameter(ParameterSetName = 'LiteralPath')]
[switch]$Characters,

[Parameter(Mandatory = $true, ParameterSetName = 'PathAll')]
[Parameter(Mandatory = $true, ParameterSetName = 'LiteralPathAll')]
[Parameter(Mandatory, ParameterSetName = 'PathAll')]
[Parameter(Mandatory, ParameterSetName = 'LiteralPathAll')]
[switch]$All,

[Parameter(ParameterSetName = 'Path')]
Expand All @@ -121,17 +113,16 @@ function Measure-Lines {
$Lines = $Words = $Characters = $true
}
elseif (($Words -eq $false) -and ($Characters -eq $false)) {
$Lines = $true
$Lines = $true
}

}
process {
if ($Path) {
$Files = Get-ChildItem -Path $Path -Recurse:$Recurse -File
}
else {
$Files = Get-ChildItem -LiteralPath $LiteralPath -File
}
}
process {
foreach ($file in $Files) {
$result = [ordered]@{ }
$result.Add('File', $file.fullname)
Expand Down Expand Up @@ -166,7 +157,7 @@ with the `LiteralPath` and `LiteralPathAll` parameter sets. Even though the
the **Path** and **LiteralPath** parameters differentiate them.

Use `Get-Command -Syntax` shows you the syntax of each parameter set. However
it does not show the name of the parameter set. The following example shows
it doesn't show the name of the parameter set. The following example shows
which parameters can be used in each parameter set.

```powershell
Expand All @@ -180,13 +171,13 @@ ParameterSetName Parameters
---------------- ----------
Path [-Path] <string[]> [-Lines] [-Words] [-Characters] [-Recurse] [<CommonParameters>]
PathAll [-Path] <string[]> -All [-Recurse] [<CommonParameters>]
LiteralPath -LiteralPath <string> [-Lines] [-Words] [-Characters] [<CommonParameters>]
LiteralPathAll -LiteralPath <string> -All [<CommonParameters>]
LiteralPath -LiteralPath <string[]> [-Lines] [-Words] [-Characters] [<CommonParameters>]
LiteralPathAll -LiteralPath <string[]> -All [<CommonParameters>]
```

### Parameter sets in action

In this example, we are using the `PathAll` parameter set.
The example uses the `PathAll` parameter set.

```powershell
Measure-Lines test* -All
Expand Down Expand Up @@ -219,3 +210,6 @@ The **Path** and **LiteralPath** parameters are unique to different parameter
sets of the `Get-ChildItem` cmdlet. When the parameters are run together in the
same cmdlet, an error is thrown. Only one parameter set can be used per cmdlet
call at a time.

<!-- link references -->
[01]: about_functions_cmdletbindingattribute.md
Loading