You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: exchange/docs-conceptual/exchange-cmdlet-syntax.md
+55-35Lines changed: 55 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,36 +3,44 @@ title: "Exchange cmdlet syntax"
3
3
ms.author: chrisda
4
4
author: chrisda
5
5
manager: deniseb
6
-
ms.date: 9/7/2023
6
+
ms.date: 07/11/2025
7
7
ms.audience: Admin
8
8
audience: Admin
9
9
ms.topic: article
10
10
ms.service: exchange-online
11
11
ms.localizationpriority: medium
12
12
ms.assetid: 85ffe9c8-7f03-4877-8e55-3cbd40228d84
13
-
description: "Learn about the structure and syntax of cmdlets in Exchange PowerShell, Exchange Online PowerShell, Security & Compliance PowerShell, and Exchange Online Protection PowerShell for on-premises environments."
13
+
description: "Learn about the structure and syntax of cmdlets in Exchange PowerShell, Exchange Online PowerShell, Security & Compliance PowerShell, and Exchange Online Protection PowerShell for cloud protection of on-premises email environments."
14
14
---
15
15
16
16
# Exchange cmdlet syntax
17
17
18
18
Exchange cmdlet reference articles use a standardized method that describes key aspects about the cmdlet. For example:
19
19
20
-
- Parameters that are available on the cmdlet.
20
+
- Parameters available on the cmdlet.
21
21
- Values that each parameter accepts.
22
22
- Parameters that can be used together, and parameters that need to be used separately.
23
23
24
-
This article explains these conventions, and also the syntax that's required to run commands in Exchange PowerShell.
24
+
This article explains these conventions, and also the syntax required to run commands in Exchange PowerShell.
25
25
26
26
## Command conventions in Exchange PowerShell
27
27
28
-
Exchange PowerShell help follows conventions that indicate what's required or optional, and how to enter parameters and values when you run a command. These command conventions are listed in the following table.
29
-
30
-
|Symbol|Description|
31
-
|---|---|
32
-
|`-`|A hyphen indicates a parameter. For example, `-Identity`.|
33
-
|`< >`|Angle brackets indicate the possible values for a parameter. For example, `-Location <ServerName>` or -Enabled \<$true \| $false\>.|
34
-
|`[ ]`|Square brackets indicate optional parameters and their values. For example, `[-WhatIf]` or `[-ResultSize <Unlimited>]`. <br/><br/> Parameter-value pairs that aren't enclosed in square brackets are required. For example, `-Password <SecureString>`. <br/><br/> Square brackets around the parameter name itself indicates a _positional_ parameter (you can use the parameter value without specifying the parameter name), and positional parameters can be required or optional. <br/><br/> For example, `Get-Mailbox [[-Identity] <MailboxIdParameter>]` means the _Identity_ parameter is positional (because it's enclosed in square brackets) and optional (because the whole parameter-value pair is enclosed in square brackets), so you can use `Get-Mailbox -Identity <MailboxIdParameter>` or `Get-Mailbox <MailboxIdParameter>`. Similarly, `Set-Mailbox [-Identity] <MailboxIdParameter>` means the _Identity_ parameter is positional (because it's enclosed in square brackets) and required (because the whole parameter-value pair isn't enclosed in square brackets), so you can use `Set-Mailbox -Identity <MailboxIdParameter>` or `Set-Mailbox <MailboxIdParameter>`.|
35
-
|`|`|Pipe symbols in parameter values indicate a choice between values. For example, -Enabled \<$true \| $false\> indicates the _Enabled_ parameter can have the value `$true` or `$false`.|
28
+
Exchange PowerShell help follows conventions to indicate required or optional information, and how to enter parameters and values when you run a command. These command conventions are described in the following list:
29
+
30
+
-`-`: A hyphen indicates a parameter. For example, `-Identity`.
31
+
-`< >`: Angle brackets indicate the possible values for a parameter. For example, `-Location <ServerName>` or `-Enabled <$true | $false>`.
32
+
-`[ ]`: Square brackets indicate optional parameters and their values. For example, `[-WhatIf]` or `[-ResultSize <Unlimited>]`.
33
+
- Parameter-value pairs not enclosed in square brackets are required. For example, `-Password <SecureString>`.
34
+
- Square brackets around the parameter name itself indicates a _positional_ parameter where you can use the parameter value without specifying the parameter name. Positional parameters are required or optional. For example:
35
+
-`Get-Mailbox [[-Identity] <MailboxIdParameter>]` means the _Identity_ parameter is:
36
+
- Positional because the parameter enclosed in square brackets.
37
+
- Optional because the whole parameter-value pair is enclosed in square brackets.
38
+
- So, you can use `Get-Mailbox -Identity <MailboxIdParameter>` or `Get-Mailbox <MailboxIdParameter>`.
39
+
-`Set-Mailbox [-Identity] <MailboxIdParameter>` means the _Identity_ parameter is:
40
+
- Positional because the parameter is enclosed in square brackets.
41
+
- Required because the whole parameter-value pair isn't enclosed in square brackets.
42
+
- So, you can use `Set-Mailbox -Identity <MailboxIdParameter>` or `Set-Mailbox <MailboxIdParameter>`.
43
+
-`|`: Pipe symbols in parameter values indicate a choice between values. For example, `-Enabled <$true | $false>` indicates the _Enabled_ parameter can have the value `$true` or `$false`.
36
44
37
45
These command conventions help you understand how a command is constructed. Except for the hyphen that indicates a parameter, you don't use these symbols as they're described in the table when you run cmdlets in Exchange PowerShell.
38
46
@@ -116,26 +124,38 @@ If you enclose the string in single quotation marks, the only special character
116
124
117
125
## Command operators in Exchange PowerShell
118
126
119
-
The following table shows the valid operators that you can use in an Exchange command. Some of these symbols were also described in the earlier [Command conventions in Exchange PowerShell](#command-conventions-in-exchange-powershell) section. However, these symbols have different meanings when they're used on the command line as operators. For example, the minus sign that's used to indicate a parameter can also be used in a command as a mathematical operator.
120
-
121
-
|Operator|Description|
122
-
|---|---|
123
-
|`=`|The equal sign is an assignment character. The value on the right side of the equal sign is assigned to the variable on the left side of the equal sign (for example, `$x= Get-Mailbox`). You can also use other characters with the equal sign: <ul><li>`+=`: Add the value on the right side of the equal sign to the current value that's contained in the variable on the left side of the equal sign.</li><li>`-=`: Subtract the value on the right side of the equal sign from the current value that's contained in the variable on the left side of the equal sign.</li><li>`*=`: Multiply the current value of the variable on the left side of the equal sign by the value that's specified on the right side of the equal sign.</li><li>`/=`: Divide the current value of the variable on the left side of the equal sign by the value that's specified on the right side of the equal sign.</li><li> `%=`: Modify the current value of the variable on the left side of the equal sign by the value that's specified on the right side of the equal sign.</li></ul>|
124
-
|`:`|Use a colon to separate a parameter's name from the parameter's value. For example, `-Enabled:$True`. A colon separator works and is optional on virtually all parameter-value pairs. A colon separator is required on switch parameters. For more information about switch parameters, see [about_Parameters](/powershell/module/microsoft.powershell.core/about/about_parameters).|
125
-
|`!`|The exclamation point is the logical NOT operator. The combined pair `!=` means "not equal to."|
126
-
|`[ ]`|Brackets specify the index value of an array position. Index values are offsets that always start at zero. For example, in the array named `$Red`, the value of the tenth position in the array is `$Red[9]`. <br/><br/> Brackets can also assign a type to a variable. For example, to identify the variable named `$A` as XML, use `$A=[XML] "<Test><A>value</A></Test>"`. The following variable types are available: `Array`, `Bool`, `Byte`, `Char`, `Char[]`, `Decimal`, `Double`, `Float`, `Int`, `Int[]`, `Long`, `Long[]`, `RegEx`, `Single`, `ScriptBlock`, `String`, `Type`, and `XML.`|
127
-
|`{ }`|Use braces to include an expression in a command. For example, `Get-Process | Where {$_.HandleCount -gt 400}`|
128
-
|`|`|Use the pipe symbol to pipe the output of one command to another command. For example, `Get-Mailbox -Server SRV1 | Set-Mailbox -ProhibitSendQuota 2GB`.|
129
-
|`>`|Use the right-angle bracket to send the output of a command to a file. If the file already exists, the contents are overwritten. For example, `Get-TransportRule > "C:\My Documents\TransportRules.txt"`.|
130
-
|`>>`|Use double right-angle brackets to append the output of a command to an existing file. If the file doesn't exist, a new file is created. For example, `Get-TransportRule >> "C:\My Documents\TransportRules.txt"`.|
131
-
|`"`|Use double quotation marks to enclose text strings that contain spaces. As previously described, variables are replaced with their actual values.|
132
-
|`$`|The dollar sign indicates a variable. For example, to create a variable named `$Blue` with the value 10, use `$Blue = 10`. After you store the variable, you can use it as the value of a parameter.|
133
-
|`@`|The at symbol references an associative array. For more information, see [about_Arrays](/powershell/module/microsoft.powershell.core/about/about_arrays).|
134
-
|`$( )`|A dollar sign with parentheses indicates command substitution. You can use command substitution when you want to use the output of one command as an argument in another command. For example, `Get-ChildItem $(Read-Host -Prompt "Enter FileName: ")`.|
135
-
|`..`|Double-periods indicate a value range. For example, if an array contains several indexes, you can return the values of all indexes between the second and fifth indexes by running the command: `$Blue[2..5]`.|
136
-
|`+`|The plus sign operator adds two values together. For example, `6 + 6` equals `12`.|
137
-
|`-`|The minus sign operator subtracts one value from another value (for example, `12 - 6` equals `6`) or indicates a negative number (for example, `-6 * 6` equals `-36`).|
138
-
|`*`|You can use an asterisk to: <ul><li>**Match strings**: For example, `Get-User | Where-Object {$_.Department -like 'Sales*'})`</li><li>**Multiply numeric values**: For example, `6 * 6` equals `36`</li><li>**Repeat the string value a specified number of times**: For example, `"Test" * 3` equals `TestTestTest`</li></ul>|
139
-
|`/`|A forward slash divides one value by another. For example, `6 / 6` equals `1`.|
140
-
|`%`|The percent sign has the following uses: <ul><li>In a numerical evaluation, it returns the remainder from a division operator. For example, `6 % 4` equals `2`.</li><li>In a [pipeline](/powershell/module/microsoft.powershell.core/about/about_pipelines), it's shorthand for the **ForEach-Object** cmdlet. For example, `Import-Csv C:\MyFile.csv | ForEach-Object {Set-Mailbox $_.Identity -Name $_.Name}` is the same as `Import-Csv C:\MyFile.csv | % {Set-Mailbox $_.Identity -Name $_.Name}`.</li></ul>|
141
-
|`?`|The question mark character is shorthand for the **Where-Object** cmdlet. For example, `Get-Alias | Where-Object {$_.Definition -eq "Clear-Host"}` is the same as `Get-Alias | ? {$_.Definition -eq "Clear-Host"}`.|
127
+
The following list shows the valid operators you can use in an Exchange command. Some of these symbols were also described in the earlier [Command conventions in Exchange PowerShell](#command-conventions-in-exchange-powershell) section. However, these symbols have different meanings when used as operators. For example, the minus sign that indicates a parameter can also be used as a mathematical operator.
128
+
129
+
-`=`: The equal sign is an assignment character. The value on the right side of the equal sign is assigned to the variable on the left side. For example, `$x = Get-Mailbox`. You can also use other characters with the equal sign:
130
+
-`+=`: Add the value on the right side of the equal sign to the current value in the variable on the left side.
131
+
-`-=`: Subtract the value on the right side of the equal sign from the current in the variable on the left side.
132
+
-`*=`: Multiply the current value of the variable on the left side of the equal sign by the value specified on the right side.
133
+
-`/=`: Divide the current value of the variable on the left side of the equal sign by the value specified on the right side.
134
+
-`%=`: Modify the current value of the variable on the left side of the equal sign by the value specified on the right side.
135
+
-`:`: Use a colon to separate a parameter name from the parameter value. For example, `-Enabled:$True`.
136
+
- A colon separator works and is optional on virtually all parameter-value pairs.
137
+
- A colon separator is required on switch parameters. For more information about switch parameters, see [about_Parameters](/powershell/module/microsoft.powershell.core/about/about_parameters).
138
+
-`!`: The exclamation point is the logical NOT operator. The combined pair `!=` means "not equal to."
139
+
-`[ ]`: Brackets specify the index value of an array position. Index values are offsets that always start at zero. For example, in the array named `$Red`, the value of the tenth position in the array is `$Red[9]`.
140
+
141
+
Brackets can also assign a type to a variable. For example, to identify the variable named `$A` as XML, use `$A=[XML] "<Test><A>value</A></Test>"`. The following variable types are available: `Array`, `Bool`, `Byte`, `Char`, `Char[]`, `Decimal`, `Double`, `Float`, `Int`, `Int[]`, `Long`, `Long[]`, `RegEx`, `Single`, `ScriptBlock`, `String`, `Type`, and `XML.`
142
+
-`{ }`: Use braces to include an expression in a command. For example, `Get-Process | Where {$_.HandleCount -gt 400}`.
143
+
-`|`: Use the pipe symbol to pipe the output of one command to another command. For example, `Get-Mailbox -Server SRV1 | Set-Mailbox -ProhibitSendQuota 2GB`.
144
+
-`>`: Use the right-angle bracket to send the output of a command to a file. If the file already exists, the contents are overwritten. For example, `Get-TransportRule > "C:\My Documents\TransportRules.txt"`.
145
+
-`>>`: Use double right-angle brackets to append the output of a command to an existing file. If the file doesn't exist, a new file is created. For example, `Get-TransportRule >> "C:\My Documents\TransportRules.txt"`.
146
+
-`"`: Use double quotation marks to enclose text strings that contain spaces. As previously described, variables are replaced with their actual values.
147
+
-`$`: The dollar sign indicates a variable. For example, to create a variable named `$Blue` with the value 10, use `$Blue = 10`. After you store the variable, you can use it as a parameter value.
148
+
-`@`: The at symbol references an associative array. For more information, see [about_Arrays](/powershell/module/microsoft.powershell.core/about/about_arrays).
149
+
-`$( )`: A dollar sign with parentheses indicates command substitution. You can use command substitution when you want to use the output of one command as an argument in another command. For example, `Get-ChildItem $(Read-Host -Prompt "Enter FileName: ")`.
150
+
-`..`: Double-periods indicate a value range. For example, if an array contains several indexes, you can return the values of all indexes between the second and fifth indexes by running the command: `$Blue[2..5]`.
151
+
-`+`: The plus sign operator adds two values together. For example, `6 + 6` equals `12`.
152
+
-`-`: The minus sign operator subtracts one value from another value (for example, `12 - 6` equals `6`) or indicates a negative number (for example, `-6 * 6` equals `-36`).
153
+
-`*`: You can use an asterisk for the following tasks:
154
+
-**Match strings**: For example, `Get-User | Where-Object {$_.Department -like 'Sales*'})`.
155
+
-**Multiply numeric values**: For example, `6 * 6` equals `36`.
156
+
-**Repeat the string value a specified number of times**: For example, `"Test" * 3` equals `TestTestTest`.
157
+
-`/`: A forward slash divides one value by another. For example, `6 / 6` equals `1`.
158
+
-`%`: The percent sign has the following uses:
159
+
- In a numerical evaluation, it returns the remainder from a division operator. For example, `6 % 4` equals `2`.
160
+
- In a [pipeline](/powershell/module/microsoft.powershell.core/about/about_pipelines), it's shorthand for the **ForEach-Object** cmdlet. For example, `Import-Csv C:\MyFile.csv | ForEach-Object {Set-Mailbox $_.Identity -Name $_.Name}` is the same as `Import-Csv C:\MyFile.csv | % {Set-Mailbox $_.Identity -Name $_.Name}`.
161
+
-`?`: The question mark is shorthand for the **Where-Object** cmdlet. For example, `Get-Alias | Where-Object {$_.Definition -eq "Clear-Host"}` is the same as `Get-Alias | ? {$_.Definition -eq "Clear-Host"}`.|
0 commit comments