3 minutes reading time (546 words)

Connect to Exchange Online using App registration and Certificate from Azure Runbook

How to Connect to Exchange Online PowerShell using an App registration and self-signed Certificate from an Azure Automation Account Runbook

1. Getting started

Follow the steps in this guide to create an Azure AD App registration and self-signed certificate

Connect to Exchange Online using App Registration and Certificate
https://techlabs.blog/categories/automation/connect-to-exchange-online-using-app-registration-and-certificate

2. Create Azure automation account

Create resource group using PowerShell New-AzResourceGroup

$RGName = "exchange-online-test-rg"
$Location = "UK West"
$Subscription = "Azure subscription 1"

Connect-AzAccount -Subscription $Subscription
New-AzResourceGroup -Name $RGName -Location $Location 

Create Azure Automation account using PowerShell New-AzAutomationAccount

$RGName = "exchange-online-test-rg"
$AAccountName = "exchange-online-test-aa"
$Location = "UK West"
$Subscription = "Azure subscription 1"

New-AzAutomationAccount -ResourceGroupName $RGName -Name $AAccountName -Location $Location 

3. Add certificate to Automation account

Automation accounts - open Automation account "exchange-online-test-aa"

Certificates - Add a certificate

Enter certificate details

Name exotest.planetxpress.net
Browse for the certificate pfx file
Enter certificate password

4. Import PowerShell Module to Automation Account

Import the Exchange Online Management PowerShell module to the Azure Automation account

Automation Account
Modules - Add a module

Browse from gallery
Click here to browse from galllery

Search for Exchange Online and select the Exchange Online Management module

Click Select

Runtime version: 5.1
Click Import

Filter modules by status "Importing"

Wait for the module to finish importing before continuing

Repeat the steps to import the PackageManagement and PowerShellGet modules

5. Create PowerShell Runbook

Automation Account
Runbooks - Create a runbook

Name: connect-exchange-online
Runbook type: PowerShell
Runtime version: 5.1

Click Create

6. Connect to Exchange online using App registration from Azure runbook

Copy and paste the PowerShell, then click Save

# Connect to Exchange Online
$CertThumbPrint = "xxxxxxxxxxxxxxx0b46fa6558a850644dfc8aafc"
$AppID = "xxxxxxxx-xxxx-xxxx-8854-08fc098067fd"
$Org = "planetxpressnet.onmicrosoft.com"

Connect-ExchangeOnline -CertificateThumbPrint $CertThumbPrint -AppID $AppID -Organization $Org

# Get Mailboxes
$Mailboxes = Get-Mailbox -ResultSize 5 
Write-Output $Mailboxes | format-table 

Open the Test pane

Start test

References:

App-only authentication for unattended scripts in Exchange Online PowerShell
https://learn.microsoft.com/en-us/powershell/exchange/app-only-auth-powershell-v2

Related Posts

 

Comments

No comments made yet. Be the first to submit a comment
Already Registered? Login Here
Monday, 26 October 2026
You can help support this website by buying me a coffee!
Buy Me A Coffee