all keyword
The all keyword is a powerful way to accomplish several useful scenarios with a very natural syntax.
all can get all of a set of things that match a criteria and run one or more post-conditions.
EXAMPLE 1
& {
$glitters = @{glitters=$true}
all that glitters
}.Transpile()EXAMPLE 2
function mallard([switch]$Quack) { $Quack }
Get-Command mallard | Get-Member | Select-Object -ExpandProperty TypeName -Unique
all functions that quack are ducks
Get-Command mallard | Get-Member | Select-Object -ExpandProperty TypeName -UniqueEXAMPLE 3
. {
$numbers = 1..100
$null = all $numbers where { ($_ % 2) -eq 1 } are odd
$null = all $numbers where { ($_ % 2) -eq 0 } are even
}.Transpile()
@(
. { all even $numbers }.Transpile()
).Length
@(
. { all odd $numbers }.Transpile()
).LengthThe input to be searched.
| Type | Required | Position | PipelineInput | Aliases |
|---|---|---|---|---|
[Object] |
false | 1 | true (ByPropertyName) | In Of The Object |
If set, include all functions in the input.
| Type | Required | Position | PipelineInput | Aliases |
|---|---|---|---|---|
[Switch] |
false | named | false | Function |
If set, include all commands in the input.
| Type | Required | Position | PipelineInput | Aliases |
|---|---|---|---|---|
[Switch] |
false | named | false | Command |
If set, include all cmdlets in the input
| Type | Required | Position | PipelineInput | Aliases |
|---|---|---|---|---|
[Switch] |
false | named | false | Cmdlet |
If set, include all aliases in the input
| Type | Required | Position | PipelineInput | Aliases |
|---|---|---|---|---|
[Switch] |
false | named | false | Alias |
If set, include all applications in the input
| Type | Required | Position | PipelineInput | Aliases |
|---|---|---|---|---|
[Switch] |
false | named | false | Application |
If set, include all applications in the input
| Type | Required | Position | PipelineInput | Aliases |
|---|---|---|---|---|
[Switch] |
false | named | false | ExternalScript Script ExternalScripts |
If set, include all variables in the inputObject.
| Type | Required | Position | PipelineInput | Aliases |
|---|---|---|---|---|
[Switch] |
false | named | false | Variable |
If set, will include all of the variables, aliases, functions, and scripts in the current directory.
| Type | Required | Position | PipelineInput | Aliases |
|---|---|---|---|---|
[Switch] |
false | named | false | Thing |
A condition. If the condition is a ScriptBlock, it will act similar to Where-Object. If the condition is not a script block, the conditional will be inferred by the word choice. For example:
all functions matching PipeScriptwill return all functions that match the pattern 'PipeScript' Or:
all in 1..100 greater than 50will return all numbers in 1..100 that are greater than 50. Often, these conditionals will be checked against multiple targets. For example:
all cmdlets that IDWill check all cmdlets to see if:
- they are named "ID"
- OR they have members named "ID"
- OR they have parameters named "ID"
- OR their PSTypenames contains "ID"
| Type | Required | Position | PipelineInput | Aliases |
|---|---|---|---|---|
[Object] |
false | 2 | true (ByPropertyName) | That Are That Have That Condition Where-Object With a With the With That Match Match Matching That Matches Match Expression Match Regular Expression Match Pattern Matches Pattern That Are Like Like Like Wildcard Greater Than Greater Greater Than Or Equal GT GE Less Than Less Less Than Or Equal LT LE |
An action that will be run on every returned item. As with the -Where parameter, the word choice used for For can be impactful. In most circumstances, passing a [ScriptBlock] will work similarly to a foreach statment. When "Should" is present within the word choice, it attach that script as an expectation that can be checked later.
| Type | Required | Position | PipelineInput | Aliases |
|---|---|---|---|---|
[Object] |
false | 3 | true (ByPropertyName) | Is Are Foreach Foreach-Object Can And Can Could And Could Should And Should Is A And Is A Is An And Is An Are a And Are a Are an And Are An |
The way to sort data before it is outputted.
| Type | Required | Position | PipelineInput | Aliases |
|---|---|---|---|---|
[Object] |
false | 4 | true (ByPropertyName) | sorted by sort by sort on sorted on sorted Sort-Object |
If output should be sorted in descending order.
| Type | Required | Position | PipelineInput | Aliases |
|---|---|---|---|---|
[Switch] |
false | named | true (ByPropertyName) | ascending |
The Command AST. This parameter and parameter set are present so that this command can be transpiled from source, and are unlikely to be used.
| Type | Required | Position | PipelineInput |
|---|---|---|---|
[CommandAst] |
true | named | true (ByValue) |
All [[-InputObject] <Object>] [-Functions] [-Commands] [-Cmdlets] [-Aliases] [-Applications] [-Scripts] [-Variables] [-Things] [[-Where] <Object>] [[-For] <Object>] [[-Sort] <Object>] [-Descending] -CommandAst <CommandAst> [<CommonParameters>]