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/app-only-auth-powershell-v2.md
+27-31Lines changed: 27 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: App-only authentication in Exchange Online PowerShell and Security & Comp
3
3
ms.author: chrisda
4
4
author: chrisda
5
5
manager: orspodek
6
-
ms.date: 08/11/2025
6
+
ms.date: 10/24/2025
7
7
ms.audience: Admin
8
8
audience: Admin
9
9
ms.topic: article
@@ -19,7 +19,7 @@ description: "Learn how to configure app-only authentication (also known as cert
19
19
20
20
# App-only authentication for unattended scripts in Exchange Online PowerShell and Security & Compliance PowerShell
21
21
22
-
Auditing and reporting scenarios in Microsoft 365 often involve unattended scripts in Exchange Online PowerShell and Security & Compliance PowerShell. In the past, unattended sign in required you to store the username and password in a local file or in a secret vault that's accessed at run-time. But, as we all know, storing user credentials locally isn't a good security practice.
22
+
Auditing and reporting scenarios in Microsoft 365 often involve unattended scripts in Exchange Online PowerShell and Security & Compliance PowerShell. In the past, unattended sign in required you to store the username and password in a local file or in a secret vault accessed at run-time. But, as we all know, storing user credentials locally isn't a good security practice.
23
23
24
24
Certificate based authentication (CBA) or app-only authentication as described in this article supports unattended script and automation scenarios by using Microsoft Entra apps and self-signed certificates.
25
25
@@ -28,16 +28,16 @@ Certificate based authentication (CBA) or app-only authentication as described i
28
28
> - Did you know that you can connect to Exchange Online PowerShell using managed identities in Azure? Check out [Use Azure managed identities to connect to Exchange Online PowerShell](connect-exo-powershell-managed-identity.md).
29
29
>
30
30
> - The features and procedures described in this article require the following versions of the Exchange Online PowerShell module:
31
-
> -**Exchange Online PowerShell (Connect-ExchangeOnline)**: Version 2.0.3 or later.
31
+
> -**Exchange Online PowerShell (Connect-ExchangeOnline)**: Version 2.0.4 or later.
32
32
> -**Security & Compliance PowerShell (Connect-IPPSSession)**: Version 3.0.0 or later.
33
33
>
34
-
> For instructions on how to install or update the module, see [Install and maintain the Exchange Online PowerShell module](exchange-online-powershell-v2.md#install-and-maintain-the-exchange-online-powershell-module). For instructions on how to use the module in Azure automation, see [Manage modules in Azure Automation](/azure/automation/shared-resources/modules).
34
+
> For instructions on how to install or update the module, see [Install and maintain the Exchange Online PowerShell module](exchange-online-powershell-v2.md#install-and-maintain-the-exchange-online-powershell-module). For instructions on how to use the module in Azure Automation, see [Manage modules in Azure Automation](/azure/automation/shared-resources/modules).
35
35
>
36
36
> - CBA or app-only authentication is available in Office 365 operated by 21Vianet in China.
37
37
>
38
38
> - REST API connections in the Exchange Online PowerShell V3 module require the PowerShellGet and PackageManagement modules. For more information, see [PowerShellGet for REST-based connections in Windows](exchange-online-powershell-v2.md#powershellget-for-rest-api-connections-in-windows).
39
39
>
40
-
> If the procedures in this article don't work for you, verify that you don't have Beta versions of the PackageManagement or PowerShellGet modules installed by running the following command: `Get-InstalledModule PackageManagement -AllVersions; Get-InstalledModule PowerShellGet -AllVersions`.
40
+
> If the procedures in this article don't work for you, verify that you don't have preview versions of the PackageManagement or PowerShellGet modules installed by running the following command: `Get-InstalledModule PackageManagement -AllVersions; Get-InstalledModule PowerShellGet -AllVersions`.
41
41
>
42
42
> - In Exchange Online PowerShell, you can't use the procedures in this article with the following Microsoft 365 Group cmdlets:
@@ -47,12 +47,13 @@ Certificate based authentication (CBA) or app-only authentication as described i
47
47
>
48
48
> You can use Microsoft Graph to replace most of the functionality from those cmdlets. For more information, see [Working with groups in Microsoft Graph](/graph/api/resources/groups-overview).
49
49
>
50
-
> - In Security & Compliance PowerShell, you can't use the procedures in this article with the following Microsoft 365 Group cmdlets:
50
+
> - In Security & Compliance PowerShell, you can't use the procedures in this article with the following Microsoft Purview cmdlets:
> - Delegated scenarios are supported in Exchange Online. The recommended method for connecting with delegation is using GDAP and App Consent. For more information, see [Use the Exchange Online PowerShell v3 Module with GDAP and App Consent](/powershell/partnercenter/exchange-online-gdap-app). You can also use multi-tenant applications when CSP relationships are not created with the customer. The required steps for using multi-tenant applications are called out within the regular instructions in this article.
56
+
> - Delegated scenarios are supported in Exchange Online. The recommended method for connecting with delegation is using GDAP and App Consent. For more information, see [Use the Exchange Online PowerShell v3 Module with GDAP and App Consent](/powershell/partnercenter/exchange-online-gdap-app). You can also use multitenant applications when CSP relationships aren't created with the customer. The required steps for using multitenant applications are called out within the regular instructions in this article.
56
57
>
57
58
> - Use the _SkipLoadingFormatData_ switch on the **Connect-ExchangeOnline** cmdlet if you get the following error when using the Windows PowerShell SDK to connect: `The term 'Update-ModuleManifest' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.`
58
59
@@ -69,7 +70,7 @@ The following examples show how to use the Exchange Online PowerShell module wit
69
70
>
70
71
> The following connection commands have many of the same options available as described in [Connect to Exchange Online PowerShell](connect-to-exchange-online-powershell.md) and [Connect to Security & Compliance PowerShell](connect-to-scc-powershell.md). For example:
71
72
>
72
-
> - Microsoft 365 GCC High, Microsoft 365 DoD or Microsoft 365 China (operated by 21Vianet) environments require the following additional parameters and values:
73
+
> - Microsoft 365 GCC High, Microsoft 365 DoD, or Microsoft 365 China (operated by 21Vianet) environments require the following extra parameters and values:
> - If a **Connect-IPPSSession** command presents a login prompt, run the command: `$Global:IsWindows = $true` before the **Connect-IPPSSession** command.
86
+
> - If a **Connect-IPPSSession** command presents a sign in prompt, run the command: `$Global:IsWindows = $true` before the **Connect-IPPSSession** command.
86
87
87
88
-**Connect using a certificate thumbprint**:
88
89
@@ -182,14 +183,12 @@ For a detailed visual flow about creating applications in Microsoft Entra ID, se
182
183
183
184

184
185
185
-
On the **Register an application** page that opens, configure the following settings:
186
-
186
+
4. On the **Register an application** page that opens, configure the following settings:
187
187
- **Name**: Enter something descriptive. For example, ExO PowerShell CBA.
188
-
189
188
- **Supported account types**: Verify that **Accounts in this organizational directory only (\<YourOrganizationName\> only - Single tenant)** is selected.
190
189
191
190
> [!NOTE]
192
-
> To make the application multi-tenant for **Exchange Online** delegated scenarios, select the value **Accounts in any organizational directory (Any Microsoft Entra directory - Multitenant)**.
191
+
> To make the application multitenant for **Exchange Online** delegated scenarios, select the value **Accounts in any organizational directory (Any Microsoft Entra directory - Multitenant)**.
193
192
194
193
- **Redirect URI (optional)**: This setting is optional. If you need to use it, configure the following settings:
195
194
- **Platform**: Select **Web**.
@@ -202,14 +201,14 @@ For a detailed visual flow about creating applications in Microsoft Entra ID, se
202
201
203
202
When you're finished on the **App registrations** page, select **Register**.
204
203
205
-
4. You're taken to the **Overview** page of the app you just registered. Leave this page open. You'll use it in the next step.
204
+
5. You're taken to the **Overview** page of the app you just registered. Leave this page open. You use it in the next step.
206
205
207
206
### Step 2: Assign API permissions to the application
208
207
209
208
Choose **one** of the following methods in this section to assign API permissions to the app:
210
209
211
210
- Select and assign the API permissions from the portal.
212
-
- Modify the app manifest to assign API permissions. (Microsoft 365 GCC High and DoD organizations should use this method)
211
+
- Modify the app manifest to assign API permissions. (Microsoft 365 GCC High and DoD organizations should use this method).
213
212
214
213
#### Select and assign the API permissions from the portal
215
214
@@ -234,10 +233,9 @@ Choose **one** of the following methods in this section to assign API permission
234
233
6. Back on the app **API permissions** page, verify **Office 365 Exchange Online** \> **Exchange.ManageAsApp** is listed and contains the following values:
235
234
- **Type**: **Application**.
236
235
- **Admin consent required**: **Yes**.
237
-
238
236
- **Status**: The current incorrect value is **Not granted for \<Organization\>**.
239
237
240
-
Change this value by selecting **Grant admin consent for \<Organization\>**, reading the confirmation dialog that opens, and then selecting **Yes**.
238
+
Change this value by selecting **Grant admin consent for \<Organization\>**, read the confirmation dialog that opens, and then select **Yes**.
241
239
242
240

243
241
@@ -320,10 +318,9 @@ Choose **one** of the following methods in this section to assign API permission
320
318
4. On the **API permissions** page, verify **Office 365 Exchange Online** \> **Exchange.ManageAsApp** is listed and contains the following values:
321
319
- **Type**: **Application**.
322
320
- **Admin consent required**: **Yes**.
323
-
324
321
- **Status**: The current incorrect value is **Not granted for \<Organization\>** for the **Office 365 Exchange Online** \> **Exchange.ManageAsApp** entry.
325
322
326
-
Change the **Status** value by selecting **Grant admin consent for \<Organization\>**, reading the confirmation dialog that opens, and then selecting **Yes**.
323
+
Change the **Status** value by selecting **Grant admin consent for \<Organization\>**, read the confirmation dialog that opens, and then select **Yes**.
327
324
328
325

329
326
@@ -341,7 +338,7 @@ Choose **one** of the following methods in this section to assign API permission
341
338
342
339
Create a self-signed x.509 certificate using one of the following methods:
343
340
344
-
- (Recommended) Use the [New-SelfSignedCertificate](/powershell/module/pki/new-selfsignedcertificate), [Export-Certificate](/powershell/module/pki/export-certificate) and [Export-PfxCertificate](/powershell/module/pki/export-pfxcertificate) cmdlets in an elevated (run as administrator) Windows PowerShell session to request a self-signed certificate and export it to `.cer` and `.pfx` (SHA1 by default). For example:
341
+
- (Recommended) Use the [New-SelfSignedCertificate](/powershell/module/pki/new-selfsignedcertificate), [Export-Certificate](/powershell/module/pki/export-certificate), and [Export-PfxCertificate](/powershell/module/pki/export-pfxcertificate) cmdlets in an elevated (run as administrator) Windows PowerShell session to request a self-signed certificate and export it to `.cer` and `.pfx` (SHA1 by default). For example:
345
342
346
343
```powershell
347
344
# Create certificate
@@ -388,16 +385,16 @@ After you register the certificate with your application, you can use the privat
388
385
389
386

390
387
391
-
4. Close the current **Certificates & secrets** page, and then the **App registrations** page to return to the main <https://portal.azure.com/> page. You'll use it in the next step.
388
+
4. Close the current **Certificates & secrets** page, and then the **App registrations** page to return to the main <https://portal.azure.com/> page. You use it in the next step.
392
389
393
-
### Step 4b: Exchange Online delegated scenarios only: Grant admin consent for the multi-tenant app
390
+
### Step 4b: Exchange Online delegated scenarios only: Grant admin consent for the multitenant app
394
391
395
-
If you made the application multi-tenant for **Exchange Online** delegated scenarios in [Step 1](#step-1-register-the-application-in-microsoft-entra-id), you need to grant admin consent to the Exchange.ManageAsApp permission so the application can run cmdlets in Exchange Online **in each tenant organization**. To do this, generate an admin consent URL for each customer tenant. Before anyone uses the multi-tenant application to connect to Exchange Online in the tenant organization, an admin in the customer tenant should open the following URL:
392
+
If you made the application multitenant for **Exchange Online** delegated scenarios in [Step 1](#step-1-register-the-application-in-microsoft-entra-id), you need to grant admin consent to the Exchange.ManageAsApp permission so the application can run cmdlets in Exchange Online **in each tenant organization**. You need to generate an admin consent URL for each customer tenant. Before anyone uses the multitenant application to connect to Exchange Online in the tenant organization, an admin in the customer tenant should open the following URL:
-`<client-id>` is the ID of the multi-tenant application.
397
+
-`<client-id>` is the ID of the multitenant application.
401
398
- The default scope is used to grant application permissions.
402
399
403
400
For more information about the URL syntax, see [Request the permissions from a directory admin](/entra/identity-platform/v2-admin-consent#request-the-permissions-from-a-directory-admin).
@@ -412,13 +409,13 @@ You have two options:
412
409
> [!NOTE]
413
410
> You can also combine both methods to assign permissions. For example, you can use Microsoft Entra roles for the "Exchange Recipient Administrator" role and also assign your custom RBAC role to extend the permissions.
414
411
>
415
-
> For multi-tenant applications in **Exchange Online** delegated scenarios, you need to assign permissions in each customer tenant.
412
+
> For multitenant applications in **Exchange Online** delegated scenarios, you need to assign permissions in each customer tenant.
416
413
417
414
#### Assign Microsoft Entra roles to the application
418
415
419
416
The supported Microsoft Entra roles are described in the following table:
@@ -434,7 +431,7 @@ The supported Microsoft Entra roles are described in the following table:
434
431
- Recipient management.
435
432
- Security and protection features. For example, anti-spam, anti-malware, anti-phishing, and the associated reports.
436
433
437
-
The Security Administrator role does not have the necessary permissions for those same tasks.
434
+
The Security Administrator role doesn't have the necessary permissions for those same tasks.
438
435
439
436
² Microsoft recommends that you use roles with the fewest permissions. Using lower permissioned accounts helps improve security for your organization. Global Administrator is a highly privileged role that should be limited to emergency scenarios when you can't use an existing role.
440
437
@@ -460,7 +457,6 @@ For general instructions about assigning roles in Microsoft Entra ID, see [Assig
460
457

461
458
462
459
3. On the **Assignments** page that opens, select **Add assignments**.
463
-
464
460
-**Exchange Online PowerShell**:
465
461
466
462

@@ -475,7 +471,7 @@ For general instructions about assigning roles in Microsoft Entra ID, see [Assig
475
471
476
472
When you're finished in the **Add assignments** flyout, select **Add**.
477
473
478
-
5. Back on the **Assignments** page, verify that the role has been assigned to the app.
474
+
5. Back on the **Assignments** page, verify that the role is assigned to the app.
479
475
480
476
-**Exchange Online PowerShell**:
481
477
@@ -488,9 +484,9 @@ For general instructions about assigning roles in Microsoft Entra ID, see [Assig
488
484
#### Assign custom role groups to the application using service principals
489
485
490
486
> [!NOTE]
491
-
> You need to connect to Exchange Online PowerShell or Security & Compliance PowerShell _before_ completing steps to create a new service principal. Creating a new service principal without connecting to PowerShell won't work (your Azure App ID and Object ID are needed to create the new service principal).
487
+
> You need to connect to Exchange Online PowerShell or Security & Compliance PowerShell _before_ completing steps to create a new service principal. Creating a new service principal without connecting to PowerShell doesn't work (your Azure App ID and Object ID are needed to create the new service principal).
492
488
>
493
-
> This method is supported only when you connect to Exchange Online PowerShell or Security & Compliance PowerShell in [REST API mode](exchange-online-powershell-v2.md#rest-api-connections-in-the-exo-v3-module). Security & Compliance PowerShell supports REST API mode in v3.2.0 or later.
489
+
> This method is supported only when you connect to Exchange Online PowerShell or Security & Compliance PowerShell in [REST API mode](exchange-online-powershell-v2.md#rest-api-connections-in-the-exo-v3-module). Security & Compliance PowerShell supports REST API mode in v3.2.0 or later.
494
490
495
491
For information about creating custom role groups, see [Create role groups in Exchange Online](/exchange/permissions-exo/role-groups#create-role-groups) and [Create Email & collaboration role groups in the Microsoft Defender portal](/defender-office-365/mdo-portal-permissions#create-email--collaboration-role-groups-in-the-microsoft-defender-portal). The custom role group that you assign to the application can contain any combination of built-in and custom roles.
0 commit comments