@@ -12,21 +12,20 @@ Describes the operators that are supported by PowerShell.
12
12
13
13
## Long description
14
14
15
- An operator is a language element that you can use in a command or
16
- expression. PowerShell supports several types of operators to help you
17
- manipulate values.
15
+ An operator is a language element that you can use in a command or expression.
16
+ PowerShell supports several types of operators to help you manipulate values.
18
17
19
18
### Arithmetic Operators
20
19
21
20
Use arithmetic operators (` + ` , ` - ` , ` * ` , ` / ` , ` % ` ) to calculate values in a
22
- command or expression. With these operators, you can add, subtract,
23
- multiply, or divide values, and calculate the remainder (modulus) of a
24
- division operation.
21
+ command or expression. With these operators, you can add, subtract, multiply,
22
+ or divide values, and calculate the remainder (modulus) of a division
23
+ operation.
25
24
26
25
The addition operator concatenates elements. The multiplication operator
27
- returns the specified number of copies of each element. You can use
28
- arithmetic operators on any .NET type that implements them, such as: ` Int ` ,
29
- ` String ` , ` DateTime ` , ` Hashtable ` , and Arrays.
26
+ returns the specified number of copies of each element. You can use arithmetic
27
+ operators on any .NET type that implements them, such as: ` Int ` , ` String ` ,
28
+ ` DateTime ` , ` Hashtable ` , and Arrays.
30
29
31
30
For more information, see [ about_Arithmetic_Operators] ( about_Arithmetic_Operators.md ) .
32
31
@@ -40,9 +39,9 @@ For more information, see [about_Assignment_Operators](about_Assignment_Operator
40
39
41
40
### Comparison Operators
42
41
43
- Use comparison operators (` -eq ` , ` -ne ` , ` -gt ` , ` -lt ` , ` -le ` , ` -ge ` ) to
44
- compare values and test conditions. For example, you can compare two string
45
- values to determine whether they are equal.
42
+ Use comparison operators (` -eq ` , ` -ne ` , ` -gt ` , ` -lt ` , ` -le ` , ` -ge ` ) to compare
43
+ values and test conditions. For example, you can compare two string values to
44
+ determine whether they are equal.
46
45
47
46
The comparison operators also include operators that find or replace patterns
48
47
in text. The (` -match ` , ` -notmatch ` , ` -replace ` ) operators use regular
@@ -51,17 +50,17 @@ expressions, and (`-like`, `-notlike`) use wildcards `*`.
51
50
Containment comparison operators determine whether a test value appears in a
52
51
reference set (` -in ` , ` -notin ` , ` -contains ` , ` -notcontains ` ).
53
52
54
- Bitwise comparison operators (` -bAND ` , ` -bOR ` , ` -bXOR ` , ` -bNOT ` ) manipulate
55
- the bit patterns in values.
53
+ Bitwise comparison operators (` -bAND ` , ` -bOR ` , ` -bXOR ` , ` -bNOT ` ) manipulate the
54
+ bit patterns in values.
56
55
57
56
For more information, see [ about_Comparison_Operators] ( about_Comparison_Operators.md ) .
58
57
59
58
### Logical Operators
60
59
61
60
Use logical operators (` -and ` , ` -or ` , ` -xor ` , ` -not ` , ` ! ` ) to connect
62
- conditional statements into a single complex conditional. For example, you
63
- can use a logical ` -and ` operator to create an object filter with two
64
- different conditions.
61
+ conditional statements into a single complex conditional. For example, you can
62
+ use a logical ` -and ` operator to create an object filter with two different
63
+ conditions.
65
64
66
65
For more information, see [ about_Logical_Operators] ( about_logical_operators.md ) .
67
66
@@ -77,9 +76,9 @@ For more information, see [about_Redirection](about_Redirection.md)
77
76
78
77
### Split and Join Operators
79
78
80
- The ` -split ` and ` -join ` operators divide and combine substrings. The
81
- ` -split ` operator splits a string into substrings. The ` -join ` operator
82
- concatenates multiple strings into a single string.
79
+ The ` -split ` and ` -join ` operators divide and combine substrings. The ` -split `
80
+ operator splits a string into substrings. The ` -join ` operator concatenates
81
+ multiple strings into a single string.
83
82
84
83
For more information, see [ about_Split] ( about_Split.md ) and
85
84
[ about_Join] ( about_Join.md ) .
@@ -93,15 +92,15 @@ For more information, see [about_Type_Operators](about_Type_Operators.md).
93
92
94
93
### Unary Operators
95
94
96
- Use unary operators to increment or decrement variables or object
97
- properties and to set integers to positive or negative numbers. For
98
- example, to increment the variable ` $a ` from ` 9 ` to ` 10 ` , you type ` $a++ ` .
95
+ Use unary operators to increment or decrement variables or object properties
96
+ and to set integers to positive or negative numbers. For example, to increment
97
+ the variable ` $a ` from ` 9 ` to ` 10 ` , you type ` $a++ ` .
99
98
100
99
### Special Operators
101
100
102
101
Special operators have specific use-cases that do not fit into any other
103
- operator group. For example, special operators allow you to
104
- run commands, change a value's data type, or retrieve elements from an array.
102
+ operator group. For example, special operators allow you to run commands,
103
+ change a value's data type, or retrieve elements from an array.
105
104
106
105
#### Array subexpression operator ` @( ) `
107
106
@@ -261,8 +260,8 @@ $job = Start-Job -ScriptBlock {Get-Process -Name pwsh}
261
260
Receive-Job $job -Wait
262
261
```
263
262
264
- If you want to run multiple commands, each in their own background process
265
- but all on one line, simply place ` & ` between and after each of the commands.
263
+ If you want to run multiple commands, each in their own background process but
264
+ all on one line, simply place ` & ` between and after each of the commands.
266
265
267
266
For more information on PowerShell jobs, see [ about_Jobs] ( about_Jobs.md ) .
268
267
@@ -300,18 +299,18 @@ variables that the script creates are added to the current scope.
300
299
> distinguish the dot from the dot (` . ` ) symbol that represents the current
301
300
> directory.
302
301
303
- In the following example, the Sample.ps1 script in the current directory is
304
- run in the current scope.
302
+ In the following example, the Sample.ps1 script in the current directory is run
303
+ in the current scope.
305
304
306
305
``` powershell
307
306
. .\sample.ps1
308
307
```
309
308
310
309
#### Format operator ` -f `
311
310
312
- Formats strings by using the format method of string objects. Enter the
313
- format string on the left side of the operator and the objects to be
314
- formatted on the right side of the operator.
311
+ Formats strings by using the format method of string objects. Enter the format
312
+ string on the left side of the operator and the objects to be formatted on the
313
+ right side of the operator.
315
314
316
315
``` powershell
317
316
"{0} {1,-10} {2:N}" -f 1,"hello",[math]::pi
@@ -326,10 +325,10 @@ method and [Composite Formatting](/dotnet/standard/base-types/composite-formatti
326
325
327
326
#### Index operator ` [ ] `
328
327
329
- Selects objects from indexed collections, such as arrays and hash tables.
330
- Array indexes are zero-based, so the first object is indexed as ` [0] ` . For
331
- arrays (only), you can also use negative indexes to get the last values.
332
- Hash tables are indexed by key value.
328
+ Selects objects from indexed collections, such as arrays and hash tables. Array
329
+ indexes are zero-based, so the first object is indexed as ` [0] ` . For arrays
330
+ (only), you can also use negative indexes to get the last values. Hash tables
331
+ are indexed by key value.
333
332
334
333
```
335
334
PS> $a = 1, 2, 3
@@ -365,9 +364,9 @@ Once upon a time...
365
364
366
365
#### Pipeline operator ` | `
367
366
368
- Sends ("pipes") the output of the command that precedes it to the command
369
- that follows it. When the output includes more than one object (a
370
- "collection"), the pipeline operator sends the objects one at a time.
367
+ Sends ("pipes") the output of the command that precedes it to the command that
368
+ follows it. When the output includes more than one object (a "collection"), the
369
+ pipeline operator sends the objects one at a time.
371
370
372
371
``` powershell
373
372
Get-Process | Get-Member
@@ -376,8 +375,12 @@ Get-PSSnapin | Where-Object {$_.vendor -ne "Microsoft"}
376
375
377
376
#### Pipeline chain operators ` && ` and ` || `
378
377
379
- Conditionally execute the right-hand side pipeline
380
- based on the success of the left-hand side pipeline.
378
+ > [ !NOTE]
379
+ > This is an experimental feature. For more information see
380
+ > [ about_Experimental_Features] ( about_Experimental_Features.md ) .
381
+
382
+ Conditionally execute the right-hand side pipeline based on the success of the
383
+ left-hand side pipeline.
381
384
382
385
``` powershell
383
386
# If Get-Process successfully finds a process called notepad,
0 commit comments