Skip to content

Commit a5d797f

Browse files
committed
✨feat: add Connect-ExchangeOnlineWorkaround function for token acquisition and connection to Exchange Online
1 parent f9d4a15 commit a5d797f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function Connect-ExchangeOnlineWorkaround {
2+
# Get a token and connect to Exchange Online
3+
# Inspired by https://david-homer.blogspot.com/2025/01/exchange-online-management-powershell.html
4+
5+
<# To Do:
6+
- Choose different environments to connect to
7+
- Add error handling
8+
#>
9+
$ExoMsalPath = [System.IO.Path]::GetDirectoryName((Get-InstalledModule -Name 'ExchangeOnlineManagement').Path)
10+
Add-Type -Path "$ExoMsalPath\Microsoft.IdentityModel.Abstractions.dll"
11+
Add-Type -Path "$ExoMsalPath\Microsoft.Identity.Client.dll"
12+
[Microsoft.Identity.Client.IPublicClientApplication] $ExoApplication = [Microsoft.Identity.Client.PublicClientApplicationBuilder]::Create('fb78d390-0c51-40cd-8e17-fdbfab77341b').WithDefaultRedirectUri().Build()
13+
$ExoAuthToken = $ExoApplication.AcquireTokenInteractive([string[]]'https://outlook.office365.com/.default').ExecuteAsync().Result
14+
Connect-ExchangeOnline -AccessToken $ExoAuthToken.AccessToken -UserPrincipalName $ExoAuthToken.Account.Username
15+
}

0 commit comments

Comments
 (0)