Updates from: 06/09/2021 03:23:59
Service Microsoft Docs article Related commit history on GitHub Change details
Microsoft.PowerShell.Core About Operators (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Core/About/about_Operators.md
--- description: Describes the operators that are supported by PowerShell.
-keywords: powershell,cmdlet
Locale: en-US Previously updated : 04/22/2021 Last updated : 06/08/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Operators
Describes the operators that are supported by PowerShell.
An operator is a language element that you can use in a command or expression. PowerShell supports several types of operators to help you manipulate values.
-### Arithmetic Operators
+## Arithmetic Operators
Use arithmetic operators (`+`, `-`, `*`, `/`, `%`) to calculate values in a command or expression. With these operators, you can add, subtract, multiply,
manipulate the bit patterns in values.
For more information, see [about_Arithmetic_Operators](about_Arithmetic_Operators.md).
-### Assignment Operators
+## Assignment Operators
Use assignment operators (`=`, `+=`, `-=`, `*=`, `/=`, `%=`) to assign, change, or append values to variables. You can combine arithmetic operators with
assignment to assign the result of the arithmetic operation to a variable.
For more information, see [about_Assignment_Operators](about_Assignment_Operators.md).
-### Comparison Operators
+## Comparison Operators
Use comparison operators (`-eq`, `-ne`, `-gt`, `-lt`, `-le`, `-ge`) to compare values and test conditions. For example, you can compare two string values to
given type.
For more information, see [about_Comparison_Operators](about_Comparison_Operators.md).
-### Logical Operators
+## Logical Operators
Use logical operators (`-and`, `-or`, `-xor`, `-not`, `!`) to connect conditional statements into a single complex conditional. For example, you can
conditions.
For more information, see [about_Logical_Operators](about_logical_operators.md).
-### Redirection Operators
+## Redirection Operators
Use redirection operators (`>`, `>>`, `2>`, `2>>`, and `2>&1`) to send the output of a command or expression to a text file. The redirection operators
cmdlet to redirect output.
For more information, see [about_Redirection](about_Redirection.md)
-### Split and Join Operators
+## Split and Join Operators
The `-split` and `-join` operators divide and combine substrings. The `-split` operator splits a string into substrings. The `-join` operator concatenates
multiple strings into a single string.
For more information, see [about_Split](about_Split.md) and [about_Join](about_Join.md).
-### Type Operators
+## Type Operators
Use the type operators (`-is`, `-isnot`, `-as`) to find or change the .NET Framework type of an object. For more information, see [about_Type_Operators](about_Type_Operators.md).
-### Unary Operators
+## Unary Operators
Use the unary `++` and `--` operators to increment or decrement values and
-`-` for negation. For example, to increment the variable `$a` from `9` to
+`-` for negation. For example, to increment the variable `$a` from `9` to
`10`, you type `$a++`. For more information, see [about_Arithmetic_Operators](about_Arithmetic_Operators.md).
-### Special Operators
+## Special Operators
Special operators have specific use-cases that do not fit into any other operator group. For example, special operators allow you to run commands, change a value's data type, or retrieve elements from an array.
-#### Grouping operator `( )`
+### Grouping operator `( )`
As in other languages, `(...)` serves to override operator precedence in expressions. For example: `(1 + 2) / 3`
However, in PowerShell, there are additional behaviors.
> more information about `$?`, see > [about_Automatic_Variables](about_Automatic_Variables.md).
-#### Subexpression operator `$( )`
+### Subexpression operator `$( )`
Returns the result of one or more statements. For a single result, returns a scalar. For multiple results, returns an array. Use this when you want to use
PS> "Folder list: $((dir c:\ -dir).Name -join ', ')"
Folder list: Program Files, Program Files (x86), Users, Windows ```
-#### Array subexpression operator `@( )`
+### Array subexpression operator `@( )`
-Returns the result of one or more statements as an array. If there is only one
-item, the array has only one member.
+Returns the result of one or more statements as an array. The result is always
+an array of 0 or more objects.
```powershell
-@(Get-CimInstance win32_logicalDisk)
+PS> $list = @(Get-Process | Select-Object -First 10; Get-Service | Select-Object -First 10 )
+PS> $list.GetType()
+
+IsPublic IsSerial Name BaseType
+-------- -------- ---- --------
+True True Object[] System.Array
+
+PS> $list.Count
+20
+PS> $list = @(Get-Service | Where-Object Status -eq Starting )
+PS> $list.GetType()
+
+IsPublic IsSerial Name BaseType
+-------- -------- ---- --------
+True True Object[] System.Array
+
+PS> $list.Count
+0
```
-#### Hash table literal syntax `@{}`
+### Hash table literal syntax `@{}`
Similar to the array subexpression, this syntax is used to declare a hash table. For more information, see [about_Hash_Tables](about_Hash_Tables.md).
-#### Call operator `&`
+### Call operator `&`
Runs a command, script, or script block. The call operator, also known as the "invocation operator", lets you run commands that are stored in variables and
Hello World!
For more about script blocks, see [about_Script_Blocks](about_Script_Blocks.md).
-#### Cast operator `[ ]`
+### Cast operator `[ ]`
Converts or limits objects to the specified type. If the objects cannot be converted, PowerShell generates an error.
converted, PowerShell generates an error.
A cast can also be performed when a variable is assigned to using [cast notation](about_Variables.md).
-#### Comma operator `,`
+### Comma operator `,`
As a binary operator, the comma creates an array or appends to the array being created. In expression mode, as a unary operator, the comma creates an array
Write-Output (,1)
Since `Write-Object` expects an argument, you must put the expression in parentheses.
-#### Dot sourcing operator `.`
+### Dot sourcing operator `.`
Runs a script in the current scope so that any functions, aliases, and variables that the script creates are added to the current scope, overriding
automatic variable `$args` is preserved.
> . .\sample.ps1 > ```
-#### Format operator `-f`
+### Format operator `-f`
Formats strings by using the format method of string objects. Enter the format string on the left side of the operator and the objects to be formatted on the
foo vs. {0}
For more information, see the [String.Format](/dotnet/api/system.string.format) method and [Composite Formatting](/dotnet/standard/base-types/composite-formatting).
-#### Index operator `[ ]`
+### Index operator `[ ]`
Selects objects from indexed collections, such as arrays and hash tables. Array indexes are zero-based, so the first object is indexed as `[0]`. For arrays
intro
Once upon a time... ```
-#### Pipeline operator `|`
+### Pipeline operator `|`
Sends ("pipes") the output of the command that precedes it to the command that follows it. When the output includes more than one object (a "collection"), the
Get-Process | Get-Member
Get-Service | Where-Object {$_.StartType -eq 'Automatic'} ```
-#### Range operator `..`
+### Range operator `..`
Represents the sequential integers in an integer array, given an upper, and lower boundary.
You can also create ranges in reverse order.
5..-5 | ForEach-Object {Write-Output $_} ```
-#### Member access operator `.`
+### Member access operator `.`
Accesses the properties and methods of an object. The member name may be an expression.
$myProcess.peakWorkingSet
'OS', 'Platform' | Foreach-Object { $PSVersionTable. $_ } ```
-#### Static member operator `::`
+### Static member operator `::`
Calls the static properties and methods of a .NET Framework class. To find the static properties and methods of an object, use the Static parameter
Microsoft.PowerShell.Core About Operators (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Core/About/about_Operators.md
--- description: Describes the operators that are supported by PowerShell.
-keywords: powershell,cmdlet
Locale: en-US Previously updated : 04/22/2021 Last updated : 06/08/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Operators
Describes the operators that are supported by PowerShell.
An operator is a language element that you can use in a command or expression. PowerShell supports several types of operators to help you manipulate values.
-### Arithmetic Operators
+## Arithmetic Operators
Use arithmetic operators (`+`, `-`, `*`, `/`, `%`) to calculate values in a command or expression. With these operators, you can add, subtract, multiply,
manipulate the bit patterns in values.
For more information, see [about_Arithmetic_Operators](about_Arithmetic_Operators.md).
-### Assignment Operators
+## Assignment Operators
Use assignment operators (`=`, `+=`, `-=`, `*=`, `/=`, `%=`) to assign, change, or append values to variables. You can combine arithmetic operators with
assignment to assign the result of the arithmetic operation to a variable.
For more information, see [about_Assignment_Operators](about_Assignment_Operators.md).
-### Comparison Operators
+## Comparison Operators
Use comparison operators (`-eq`, `-ne`, `-gt`, `-lt`, `-le`, `-ge`) to compare values and test conditions. For example, you can compare two string values to
given type.
For more information, see [about_Comparison_Operators](about_Comparison_Operators.md).
-### Logical Operators
+## Logical Operators
Use logical operators (`-and`, `-or`, `-xor`, `-not`, `!`) to connect conditional statements into a single complex conditional. For example, you can
conditions.
For more information, see [about_Logical_Operators](about_logical_operators.md).
-### Redirection Operators
+## Redirection Operators
Use redirection operators (`>`, `>>`, `2>`, `2>>`, and `2>&1`) to send the output of a command or expression to a text file. The redirection operators
cmdlet to redirect output.
For more information, see [about_Redirection](about_Redirection.md)
-### Split and Join Operators
+## Split and Join Operators
The `-split` and `-join` operators divide and combine substrings. The `-split` operator splits a string into substrings. The `-join` operator concatenates
multiple strings into a single string.
For more information, see [about_Split](about_Split.md) and [about_Join](about_Join.md).
-### Type Operators
+## Type Operators
Use the type operators (`-is`, `-isnot`, `-as`) to find or change the .NET Framework type of an object. For more information, see [about_Type_Operators](about_Type_Operators.md).
-### Unary Operators
+## Unary Operators
Use the unary `++` and `--` operators to increment or decrement values and
-`-` for negation. For example, to increment the variable `$a` from `9` to
+`-` for negation. For example, to increment the variable `$a` from `9` to
`10`, you type `$a++`. For more information, see [about_Arithmetic_Operators](about_Arithmetic_Operators.md).
-### Special Operators
+## Special Operators
Special operators have specific use-cases that do not fit into any other operator group. For example, special operators allow you to run commands, change a value's data type, or retrieve elements from an array.
-#### Grouping operator `( )`
+### Grouping operator `( )`
As in other languages, `(...)` serves to override operator precedence in expressions. For example: `(1 + 2) / 3`
However, in PowerShell, there are additional behaviors.
output _collected in memory_ before the results are sent through the pipeline.
-#### Subexpression operator `$( )`
+### Subexpression operator `$( )`
Returns the result of one or more statements. For a single result, returns a scalar. For multiple results, returns an array. Use this when you want to use
PS> "Folder list: $((dir c:\ -dir).Name -join ', ')"
Folder list: Program Files, Program Files (x86), Users, Windows ```
-#### Array subexpression operator `@( )`
+### Array subexpression operator `@( )`
-Returns the result of one or more statements as an array. If there is only one
-item, the array has only one member.
+Returns the result of one or more statements as an array. The result is always
+an array of 0 or more objects.
```powershell
-@(Get-CimInstance win32_logicalDisk)
+PS> $list = @(Get-Process | Select-Object -First 10; Get-Service | Select-Object -First 10 )
+PS> $list.GetType()
+
+IsPublic IsSerial Name BaseType
+-------- -------- ---- --------
+True True Object[] System.Array
+
+PS> $list.Count
+20
+PS> $list = @(Get-Service | Where-Object Status -eq Starting )
+PS> $list.GetType()
+
+IsPublic IsSerial Name BaseType
+-------- -------- ---- --------
+True True Object[] System.Array
+
+PS> $list.Count
+0
```
-#### Hash table literal syntax `@{}`
+### Hash table literal syntax `@{}`
Similar to the array subexpression, this syntax is used to declare a hash table. For more information, see [about_Hash_Tables](about_Hash_Tables.md).
-#### Call operator `&`
+### Call operator `&`
Runs a command, script, or script block. The call operator, also known as the "invocation operator", lets you run commands that are stored in variables and
Hello World!
For more about script blocks, see [about_Script_Blocks](about_Script_Blocks.md).
-#### Background operator `&`
+### Background operator `&`
Runs the pipeline before it in the background, in a PowerShell job. This operator acts similarly to the UNIX control operator ampersand (`&`), which
Get-Process -Name pwsh & Get-Service -Name BITS & Get-CimInstance -ClassName Win
For more information on PowerShell jobs, see [about_Jobs](about_Jobs.md).
-#### Cast operator `[ ]`
+### Cast operator `[ ]`
Converts or limits objects to the specified type. If the objects cannot be converted, PowerShell generates an error.
converted, PowerShell generates an error.
A cast can also be performed when a variable is assigned to using [cast notation](about_Variables.md).
-#### Comma operator `,`
+### Comma operator `,`
As a binary operator, the comma creates an array or appends to the array being created. In expression mode, as a unary operator, the comma creates an array
Write-Output (,1)
Since `Write-Object` expects an argument, you must put the expression in parentheses.
-#### Dot sourcing operator `.`
+### Dot sourcing operator `.`
Runs a script in the current scope so that any functions, aliases, and variables that the script creates are added to the current scope, overriding
automatic variable `$args` is preserved.
> . .\sample.ps1 > ```
-#### Format operator `-f`
+### Format operator `-f`
Formats strings by using the format method of string objects. Enter the format string on the left side of the operator and the objects to be formatted on the
foo vs. {0}
For more information, see the [String.Format](/dotnet/api/system.string.format) method and [Composite Formatting](/dotnet/standard/base-types/composite-formatting).
-#### Index operator `[ ]`
+### Index operator `[ ]`
Selects objects from indexed collections, such as arrays and hash tables. Array indexes are zero-based, so the first object is indexed as `[0]`. For arrays
intro
Once upon a time... ```
-#### Pipeline operator `|`
+### Pipeline operator `|`
Sends ("pipes") the output of the command that precedes it to the command that follows it. When the output includes more than one object (a "collection"), the
Get-Process | Get-Member
Get-Service | Where-Object {$_.StartType -eq 'Automatic'} ```
-#### Pipeline chain operators `&&` and `||`
+### Pipeline chain operators `&&` and `||`
Conditionally execute the right-hand side pipeline based on the success of the left-hand side pipeline.
npm install || Remove-Item -Recurse ./node_modules
For more information, see [About_Pipeline_Chain_Operators](About_Pipeline_Chain_Operators.md).
-#### Range operator `..`
+### Range operator `..`
Represents the sequential integers in an integer array, given an upper, and lower boundary.
B
A ```
-#### Member access operator `.`
+### Member access operator `.`
Accesses the properties and methods of an object. The member name may be an expression.
$myProcess.peakWorkingSet
'OS', 'Platform' | Foreach-Object { $PSVersionTable. $_ } ```
-#### Static member operator `::`
+### Static member operator `::`
Calls the static properties and methods of a .NET Framework class. To find the static properties and methods of an object, use the Static parameter
of the `Get-Member` cmdlet. The member name may be an expression.
'MinValue', 'MaxValue' | Foreach-Object { [int]:: $_ } ```
-#### Ternary operator `? <if-true> : <if-false>`
+### Ternary operator `? <if-true> : <if-false>`
You can use the ternary operator as a replacement for the `if-else` statement in simple conditional cases. For more information, see [about_If](about_If.md).
-#### Null-coalescing operator `??`
+### Null-coalescing operator `??`
The null-coalescing operator `??` returns the value of its left-hand operand if it isn't null. Otherwise, it evaluates the right-hand operand and returns its
$todaysDate ?? (Get-Date).ToShortDateString()
1/10/2020 ```
-#### Null-coalescing assignment operator `??=`
+### Null-coalescing assignment operator `??=`
The null-coalescing assignment operator `??=` assigns the value of its right-hand operand to its left-hand operand only if the left-hand operand
$todaysDate ??= (Get-Date).ToShortDateString()
1/10/2020 ```
-#### Null-conditional operators `?.` and `?[]`
+### Null-conditional operators `?.` and `?[]`
> [!NOTE] > This is an experimental feature. For more information see
A null-conditional operator applies a member access, `?.`, or element access,
`?[]`, operation to its operand only if that operand evaluates to non-null; otherwise, it returns null.
+Since PowerShell allows `?` to be part of the variable name, formal
+specification of the variable name is required for using these operators. So it
+is required to use `{}` around the variable names like `${a}` or when `?` is
+part of the variable name `${a?}`.
+ In the following example, the value of **PropName** is returned. ```powershell
Microsoft.PowerShell.Core About Operators (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Core/About/about_Operators.md
--- description: Describes the operators that are supported by PowerShell.
-keywords: powershell,cmdlet
Locale: en-US Previously updated : 04/22/2021 Last updated : 06/08/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Operators
Describes the operators that are supported by PowerShell.
An operator is a language element that you can use in a command or expression. PowerShell supports several types of operators to help you manipulate values.
-### Arithmetic Operators
+## Arithmetic Operators
Use arithmetic operators (`+`, `-`, `*`, `/`, `%`) to calculate values in a command or expression. With these operators, you can add, subtract, multiply,
manipulate the bit patterns in values.
For more information, see [about_Arithmetic_Operators](about_Arithmetic_Operators.md).
-### Assignment Operators
+## Assignment Operators
Use assignment operators (`=`, `+=`, `-=`, `*=`, `/=`, `%=`) to assign, change, or append values to variables. You can combine arithmetic operators with
assignment to assign the result of the arithmetic operation to a variable.
For more information, see [about_Assignment_Operators](about_Assignment_Operators.md).
-### Comparison Operators
+## Comparison Operators
Use comparison operators (`-eq`, `-ne`, `-gt`, `-lt`, `-le`, `-ge`) to compare values and test conditions. For example, you can compare two string values to
given type.
For more information, see [about_Comparison_Operators](about_Comparison_Operators.md).
-### Logical Operators
+## Logical Operators
Use logical operators (`-and`, `-or`, `-xor`, `-not`, `!`) to connect conditional statements into a single complex conditional. For example, you can
conditions.
For more information, see [about_Logical_Operators](about_logical_operators.md).
-### Redirection Operators
+## Redirection Operators
Use redirection operators (`>`, `>>`, `2>`, `2>>`, and `2>&1`) to send the output of a command or expression to a text file. The redirection operators
cmdlet to redirect output.
For more information, see [about_Redirection](about_Redirection.md)
-### Split and Join Operators
+## Split and Join Operators
The `-split` and `-join` operators divide and combine substrings. The `-split` operator splits a string into substrings. The `-join` operator concatenates
multiple strings into a single string.
For more information, see [about_Split](about_Split.md) and [about_Join](about_Join.md).
-### Type Operators
+## Type Operators
Use the type operators (`-is`, `-isnot`, `-as`) to find or change the .NET Framework type of an object. For more information, see [about_Type_Operators](about_Type_Operators.md).
-### Unary Operators
+## Unary Operators
Use the unary `++` and `--` operators to increment or decrement values and
-`-` for negation. For example, to increment the variable `$a` from `9` to
+`-` for negation. For example, to increment the variable `$a` from `9` to
`10`, you type `$a++`. For more information, see [about_Arithmetic_Operators](about_Arithmetic_Operators.md).
-### Special Operators
+## Special Operators
Special operators have specific use-cases that do not fit into any other operator group. For example, special operators allow you to run commands, change a value's data type, or retrieve elements from an array.
-#### Grouping operator `( )`
+### Grouping operator `( )`
As in other languages, `(...)` serves to override operator precedence in expressions. For example: `(1 + 2) / 3`
However, in PowerShell, there are additional behaviors.
output _collected in memory_ before the results are sent through the pipeline.
-#### Subexpression operator `$( )`
+### Subexpression operator `$( )`
Returns the result of one or more statements. For a single result, returns a scalar. For multiple results, returns an array. Use this when you want to use
PS> "Folder list: $((dir c:\ -dir).Name -join ', ')"
Folder list: Program Files, Program Files (x86), Users, Windows ```
-#### Array subexpression operator `@( )`
+### Array subexpression operator `@( )`
-Returns the result of one or more statements as an array. If there is only one
-item, the array has only one member.
+Returns the result of one or more statements as an array. The result is always
+an array of 0 or more objects.
```powershell
-@(Get-CimInstance win32_logicalDisk)
+PS> $list = @(Get-Process | Select-Object -First 10; Get-Service | Select-Object -First 10 )
+PS> $list.GetType()
+
+IsPublic IsSerial Name BaseType
+-------- -------- ---- --------
+True True Object[] System.Array
+
+PS> $list.Count
+20
+PS> $list = @(Get-Service | Where-Object Status -eq Starting )
+PS> $list.GetType()
+
+IsPublic IsSerial Name BaseType
+-------- -------- ---- --------
+True True Object[] System.Array
+
+PS> $list.Count
+0
```
-#### Hash table literal syntax `@{}`
+### Hash table literal syntax `@{}`
Similar to the array subexpression, this syntax is used to declare a hash table. For more information, see [about_Hash_Tables](about_Hash_Tables.md).
-#### Call operator `&`
+### Call operator `&`
Runs a command, script, or script block. The call operator, also known as the "invocation operator", lets you run commands that are stored in variables and
Hello World!
For more about script blocks, see [about_Script_Blocks](about_Script_Blocks.md).
-#### Background operator `&`
+### Background operator `&`
Runs the pipeline before it in the background, in a PowerShell job. This operator acts similarly to the UNIX control operator ampersand (`&`), which
Get-Process -Name pwsh & Get-Service -Name BITS & Get-CimInstance -ClassName Win
For more information on PowerShell jobs, see [about_Jobs](about_Jobs.md).
-#### Cast operator `[ ]`
+### Cast operator `[ ]`
Converts or limits objects to the specified type. If the objects cannot be converted, PowerShell generates an error.
converted, PowerShell generates an error.
A cast can also be performed when a variable is assigned to using [cast notation](about_Variables.md).
-#### Comma operator `,`
+### Comma operator `,`
As a binary operator, the comma creates an array or appends to the array being created. In expression mode, as a unary operator, the comma creates an array
Write-Output (,1)
Since `Write-Object` expects an argument, you must put the expression in parentheses.
-#### Dot sourcing operator `.`
+### Dot sourcing operator `.`
Runs a script in the current scope so that any functions, aliases, and variables that the script creates are added to the current scope, overriding
automatic variable `$args` is preserved.
> . .\sample.ps1 > ```
-#### Format operator `-f`
+### Format operator `-f`
Formats strings by using the format method of string objects. Enter the format string on the left side of the operator and the objects to be formatted on the
foo vs. {0}
For more information, see the [String.Format](/dotnet/api/system.string.format) method and [Composite Formatting](/dotnet/standard/base-types/composite-formatting).
-#### Index operator `[ ]`
+### Index operator `[ ]`
Selects objects from indexed collections, such as arrays and hash tables. Array indexes are zero-based, so the first object is indexed as `[0]`. For arrays
intro
Once upon a time... ```
-#### Pipeline operator `|`
+### Pipeline operator `|`
Sends ("pipes") the output of the command that precedes it to the command that follows it. When the output includes more than one object (a "collection"), the
Get-Process | Get-Member
Get-Service | Where-Object {$_.StartType -eq 'Automatic'} ```
-#### Pipeline chain operators `&&` and `||`
+### Pipeline chain operators `&&` and `||`
Conditionally execute the right-hand side pipeline based on the success of the left-hand side pipeline.
npm install || Remove-Item -Recurse ./node_modules
For more information, see [About_Pipeline_Chain_Operators](About_Pipeline_Chain_Operators.md).
-#### Range operator `..`
+### Range operator `..`
Represents the sequential integers in an integer array, given an upper, and lower boundary.
B
A ```
-#### Member access operator `.`
+### Member access operator `.`
Accesses the properties and methods of an object. The member name may be an expression.
$myProcess.peakWorkingSet
'OS', 'Platform' | Foreach-Object { $PSVersionTable. $_ } ```
-#### Static member operator `::`
+### Static member operator `::`
Calls the static properties and methods of a .NET Framework class. To find the static properties and methods of an object, use the Static parameter
of the `Get-Member` cmdlet. The member name may be an expression.
'MinValue', 'MaxValue' | Foreach-Object { [int]:: $_ } ```
-#### Ternary operator `? <if-true> : <if-false>`
+### Ternary operator `? <if-true> : <if-false>`
You can use the ternary operator as a replacement for the `if-else` statement in simple conditional cases. For more information, see [about_If](about_If.md).
-#### Null-coalescing operator `??`
+### Null-coalescing operator `??`
The null-coalescing operator `??` returns the value of its left-hand operand if it isn't null. Otherwise, it evaluates the right-hand operand and returns its
$todaysDate ?? (Get-Date).ToShortDateString()
1/10/2020 ```
-#### Null-coalescing assignment operator `??=`
+### Null-coalescing assignment operator `??=`
The null-coalescing assignment operator `??=` assigns the value of its right-hand operand to its left-hand operand only if the left-hand operand
$todaysDate ??= (Get-Date).ToShortDateString()
1/10/2020 ```
-#### Null-conditional operators `?.` and `?[]`
+### Null-conditional operators `?.` and `?[]`
> [!NOTE] > This feature was moved from experimental to mainstream in PowerShell 7.1.
Microsoft.PowerShell.Core About Operators (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/About/about_Operators.md
--- description: Describes the operators that are supported by PowerShell. Locale: en-US Previously updated : 04/22/2021 Last updated : 06/08/2021 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Operators
Describes the operators that are supported by PowerShell.
An operator is a language element that you can use in a command or expression. PowerShell supports several types of operators to help you manipulate values.
-### Arithmetic Operators
+## Arithmetic Operators
Use arithmetic operators (`+`, `-`, `*`, `/`, `%`) to calculate values in a command or expression. With these operators, you can add, subtract, multiply,
manipulate the bit patterns in values.
For more information, see [about_Arithmetic_Operators](about_Arithmetic_Operators.md).
-### Assignment Operators
+## Assignment Operators
Use assignment operators (`=`, `+=`, `-=`, `*=`, `/=`, `%=`) to assign, change, or append values to variables. You can combine arithmetic operators with
assignment to assign the result of the arithmetic operation to a variable.
For more information, see [about_Assignment_Operators](about_Assignment_Operators.md).
-### Comparison Operators
+## Comparison Operators
Use comparison operators (`-eq`, `-ne`, `-gt`, `-lt`, `-le`, `-ge`) to compare values and test conditions. For example, you can compare two string values to
given type.
For more information, see [about_Comparison_Operators](about_Comparison_Operators.md).
-### Logical Operators
+## Logical Operators
Use logical operators (`-and`, `-or`, `-xor`, `-not`, `!`) to connect conditional statements into a single complex conditional. For example, you can
conditions.
For more information, see [about_Logical_Operators](about_logical_operators.md).
-### Redirection Operators
+## Redirection Operators
Use redirection operators (`>`, `>>`, `2>`, `2>>`, and `2>&1`) to send the output of a command or expression to a text file. The redirection operators
cmdlet to redirect output.
For more information, see [about_Redirection](about_Redirection.md)
-### Split and Join Operators
+## Split and Join Operators
The `-split` and `-join` operators divide and combine substrings. The `-split` operator splits a string into substrings. The `-join` operator concatenates
multiple strings into a single string.
For more information, see [about_Split](about_Split.md) and [about_Join](about_Join.md).
-### Type Operators
+## Type Operators
Use the type operators (`-is`, `-isnot`, `-as`) to find or change the .NET Framework type of an object. For more information, see [about_Type_Operators](about_Type_Operators.md).
-### Unary Operators
+## Unary Operators
Use the unary `++` and `--` operators to increment or decrement values and
-`-` for negation. For example, to increment the variable `$a` from `9` to
+`-` for negation. For example, to increment the variable `$a` from `9` to
`10`, you type `$a++`. For more information, see [about_Arithmetic_Operators](about_Arithmetic_Operators.md).
-### Special Operators
+## Special Operators
Special operators have specific use-cases that do not fit into any other operator group. For example, special operators allow you to run commands, change a value's data type, or retrieve elements from an array.
-#### Grouping operator `( )`
+### Grouping operator `( )`
As in other languages, `(...)` serves to override operator precedence in expressions. For example: `(1 + 2) / 3`
However, in PowerShell, there are additional behaviors.
output _collected in memory_ before the results are sent through the pipeline.
-#### Subexpression operator `$( )`
+### Subexpression operator `$( )`
Returns the result of one or more statements. For a single result, returns a scalar. For multiple results, returns an array. Use this when you want to use
PS> "Folder list: $((dir c:\ -dir).Name -join ', ')"
Folder list: Program Files, Program Files (x86), Users, Windows ```
-#### Array subexpression operator `@( )`
+### Array subexpression operator `@( )`
-Returns the result of one or more statements as an array. If there is only one
-item, the array has only one member.
+Returns the result of one or more statements as an array. The result is always
+an array of 0 or more objects.
```powershell
-@(Get-CimInstance win32_logicalDisk)
+PS> $list = @(Get-Process | Select-Object -First 10; Get-Service | Select-Object -First 10 )
+PS> $list.GetType()
+
+IsPublic IsSerial Name BaseType
+-------- -------- ---- --------
+True True Object[] System.Array
+
+PS> $list.Count
+20
+PS> $list = @(Get-Service | Where-Object Status -eq Starting )
+PS> $list.GetType()
+
+IsPublic IsSerial Name BaseType
+-------- -------- ---- --------
+True True Object[] System.Array
+
+PS> $list.Count
+0
```
-#### Hash table literal syntax `@{}`
+### Hash table literal syntax `@{}`
Similar to the array subexpression, this syntax is used to declare a hash table. For more information, see [about_Hash_Tables](about_Hash_Tables.md).
-#### Call operator `&`
+### Call operator `&`
Runs a command, script, or script block. The call operator, also known as the "invocation operator", lets you run commands that are stored in variables and
Hello World!
For more about script blocks, see [about_Script_Blocks](about_Script_Blocks.md).
-#### Background operator `&`
+### Background operator `&`
Runs the pipeline before it in the background, in a PowerShell job. This operator acts similarly to the UNIX control operator ampersand (`&`), which
Get-Process -Name pwsh & Get-Service -Name BITS & Get-CimInstance -ClassName Win
For more information on PowerShell jobs, see [about_Jobs](about_Jobs.md).
-#### Cast operator `[ ]`
+### Cast operator `[ ]`
Converts or limits objects to the specified type. If the objects cannot be converted, PowerShell generates an error.
converted, PowerShell generates an error.
A cast can also be performed when a variable is assigned to using [cast notation](about_Variables.md).
-#### Comma operator `,`
+### Comma operator `,`
As a binary operator, the comma creates an array or appends to the array being created. In expression mode, as a unary operator, the comma creates an array
Write-Output (,1)
Since `Write-Object` expects an argument, you must put the expression in parentheses.
-#### Dot sourcing operator `.`
+### Dot sourcing operator `.`
Runs a script in the current scope so that any functions, aliases, and variables that the script creates are added to the current scope, overriding
automatic variable `$args` is preserved.
> . .\sample.ps1 > ```
-#### Format operator `-f`
+### Format operator `-f`
Formats strings by using the format method of string objects. Enter the format string on the left side of the operator and the objects to be formatted on the
foo vs. {0}
For more information, see the [String.Format](/dotnet/api/system.string.format) method and [Composite Formatting](/dotnet/standard/base-types/composite-formatting).
-#### Index operator `[ ]`
+### Index operator `[ ]`
Selects objects from indexed collections, such as arrays and hash tables. Array indexes are zero-based, so the first object is indexed as `[0]`. For arrays
intro
Once upon a time... ```
-#### Pipeline operator `|`
+### Pipeline operator `|`
Sends ("pipes") the output of the command that precedes it to the command that follows it. When the output includes more than one object (a "collection"), the
Get-Process | Get-Member
Get-Service | Where-Object {$_.StartType -eq 'Automatic'} ```
-#### Pipeline chain operators `&&` and `||`
+### Pipeline chain operators `&&` and `||`
Conditionally execute the right-hand side pipeline based on the success of the left-hand side pipeline.
npm install || Remove-Item -Recurse ./node_modules
For more information, see [About_Pipeline_Chain_Operators](About_Pipeline_Chain_Operators.md).
-#### Range operator `..`
+### Range operator `..`
Represents the sequential integers in an integer array, given an upper, and lower boundary.
B
A ```
-#### Member access operator `.`
+### Member access operator `.`
Accesses the properties and methods of an object. The member name may be an expression.
$myProcess.peakWorkingSet
'OS', 'Platform' | Foreach-Object { $PSVersionTable. $_ } ```
-#### Static member operator `::`
+### Static member operator `::`
Calls the static properties and methods of a .NET Framework class. To find the static properties and methods of an object, use the Static parameter
of the `Get-Member` cmdlet. The member name may be an expression.
'MinValue', 'MaxValue' | Foreach-Object { [int]:: $_ } ```
-#### Ternary operator `? <if-true> : <if-false>`
+### Ternary operator `? <if-true> : <if-false>`
You can use the ternary operator as a replacement for the `if-else` statement in simple conditional cases. For more information, see [about_If](about_If.md).
-#### Null-coalescing operator `??`
+### Null-coalescing operator `??`
The null-coalescing operator `??` returns the value of its left-hand operand if it isn't null. Otherwise, it evaluates the right-hand operand and returns its
$todaysDate ?? (Get-Date).ToShortDateString()
1/10/2020 ```
-#### Null-coalescing assignment operator `??=`
+### Null-coalescing assignment operator `??=`
The null-coalescing assignment operator `??=` assigns the value of its right-hand operand to its left-hand operand only if the left-hand operand
$todaysDate ??= (Get-Date).ToShortDateString()
1/10/2020 ```
-#### Null-conditional operators `?.` and `?[]`
+### Null-conditional operators `?.` and `?[]`
> [!NOTE] > This feature was moved from experimental to mainstream in PowerShell 7.1.
developer Alias Attribute Declaration https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/developer/cmdlet/alias-attribute-declaration.md
description: Alias Attribute Declaration
--- # Alias Attribute Declaration
-The Alias attribute allows the user to specify different names for a cmdlet or a cmdlet parameter.
-Aliases can be used to provide shortcuts for a parameter name, or they can provide different names
-that are appropriate for different scenarios.
+The **Alias** attribute allows the user to specify different names for a cmdlet or a cmdlet
+parameter. Aliases can be used to provide shortcuts for a parameter name, or they can provide
+different names that are appropriate for different scenarios.
## Syntax
that are appropriate for different scenarios.
[Alias(aliasNames)] ```
-#### Parameters
+### Parameters
`aliasNames` (String[]) Required. Specifies a set of comma-separated alias names for the cmdlet parameter. ## Remarks
-The Alias attribute is defined by the
+The **Alias** attribute is defined by the
[System.Management.Automation.Aliasattribute](/dotnet/api/System.Management.Automation.AliasAttribute) class.
-Cmdlet aliases
+### Cmdlet aliases
-- The Alias attribute is used with the cmdlet declaration. For more information about how to declare
- these attributes, see [Cmdlet Aliases](cmdlet-aliases.md).
+- The **Alias** attribute is used with the cmdlet declaration. For more information about how to
+ declare these attributes, see [Cmdlet Aliases](cmdlet-aliases.md).
- Each parameter alias name must be unique. Windows PowerShell does not check for duplicate alias names.
-Parameter aliases
+### Parameter aliases
-- The Alias attribute is used with the Parameter attribute when you specify a cmdlet parameter. For
- more information about how to declare these attributes, see
- [How to Declare Cmdlet Parameters](./how-to-declare-cmdlet-parameters.md).
+- The **Alias** attribute is used with the **Parameter** attribute when you specify a cmdlet
+ parameter. For more information about how to declare these attributes, see [How to Declare Cmdlet Parameters](./how-to-declare-cmdlet-parameters.md).
- Each parameter alias name must be unique within a cmdlet. Windows PowerShell does not check for duplicate alias names. - The Alias attribute is used once for each parameter in a cmdlet.
developer Cmdlet Aliases https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/developer/cmdlet/cmdlet-aliases.md
Follow these guidelines when you create built-in aliases for your cmdlets:
- Include an alias prefix that references the verb of the cmdlet name and an alias suffix that references the noun of the cmdlet name. For example, the alias for the `Import-Module` cmdlet is
- "ipmo". For a list of all the verbs and their aliases, see
+ `ipmo`. For a list of all the verbs and their aliases, see
[Cmdlet Verbs](./approved-verbs-for-windows-powershell-commands.md). - For cmdlets that have the same verb, include the same alias prefix. For example, the aliases for
lang-spec Chapter 02 https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/lang-spec/chapter-02.md
context, is a *command-name* or a *command-argument*.)
The keywords `class`, `define`, `from`, `using`, and `var` are reserved for future use.
+> [!NOTE]
+> Editor's Note: The `class` and `using` keywords were introduced in PowerShell 5.0. See
+> [about_Classes](/powershell/module/microsoft.powershell.core/about/about_classes) and
+> [about_Using](/powershell/module/microsoft.powershell.core/about/about_using).
+ ### 2.3.2 Variables Syntax:
There are three kinds of argument:
Get-Power -exponent 3 -base 5 ``` -- Positional argument ([§8.10.2][]) -- Arguments and their corresponding parameters inside commands
+- Positional argument ([§8.10.2][]) - Arguments and their corresponding parameters inside commands
have positions with the first having position zero. The argument in position 0 is bound to the parameter in position 0; the argument in position 1 is bound to the parameter in position 1; and so on. For example, given a command `Get-Power`, that has parameters `$base` and `$exponent` in
Description:
`&&` and `||` are reserved for future use.
+> [!NOTE]
+> Editor's Note: The pipeline chain operators `&&` and `||` were introduced in PowerShell 7. See
+> [about_Pipeline_Chain_Operators](/powershell/module/microsoft.powershell.core/about/about_pipeline_chain_operators).
+ The name following *dash* in an operator is reserved for that purpose only in an operator context. An operator that begins with *dash* must not have any white space between that *dash* and the token
lang-spec Chapter 08 https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/lang-spec/chapter-08.md
governing arguments are as follows:
- An argument of `--` indicates that all arguments following it are to be passed in their actual form as though double quotes were placed around them.
+ > [!NOTE]
+ > Editor's note: The `--` argument was never implemented.
+ - An argument of `--%` indicates that all arguments following it are to be passed with minimal parsing and processing. This argument is called the verbatim parameter. Arguments after the verbatim parameter are not PowerShell expressions even if they are syntactically valid PowerShell
lang-spec Chapter 11 https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/lang-spec/chapter-11.md
variable **PSModulePath**.
The following cmdlets deal with modules: -- [Get-Module](xref:Microsoft.PowerShell.Core.Get-Module): Identifies the modules that have been, or that can be, imported-- [Import-Module](xref:Microsoft.PowerShell.Core.Import-Module): Adds one or more modules to the current session (see [§11.4][])-- [Export-ModuleMember](xref:Microsoft.PowerShell.Core.Export-ModuleMember): Identifies the module members that are to be exported-- [Remove-Module](xref:Microsoft.PowerShell.Core.Remove-Module): Removes one or more modules from the current session (see [§11.5][])
+- [Get-Module](xref:Microsoft.PowerShell.Core.Get-Module): Identifies the modules that have been, or
+can be imported
+- [Import-Module](xref:Microsoft.PowerShell.Core.Import-Module): Adds one or more modules to the
+ current session (see [§11.4][])
+- [Export-ModuleMember](xref:Microsoft.PowerShell.Core.Export-ModuleMember): Identifies the module
+ members that are to be exported
+- [Remove-Module](xref:Microsoft.PowerShell.Core.Remove-Module): Removes one or more modules from
+ the current session (see [§11.5][])
- [New-Module](xref:Microsoft.PowerShell.Core.New-Module): Creates a dynamic module (see [§11.7][]) ## 11.2 Writing a script module