Markus
Markus

Reputation: 624

Connect to Exchange from PowerShell on Linux

I tried to follow the instructions on https://learn.microsoft.com/de-de/powershell/exchange/connect-to-exchange-online-powershell?view=exchange-ps, but they do not seem to work on Linux:

$ pwsh
PowerShell 7.1.0
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS /home/info> Install-Module -Name ExchangeOnlineManagement

PS /home/info> $O365Credential = Get-Credential                                                                                                                                                                  
PowerShell credential request
Enter your credentials.
User: [email protected]
Password for user [email protected]: ***********

PS /home/info> Connect-ExchangeOnline -Credential $UserCredential                                                                                                                                                                                                           ----------------------------------------------------------------------------                                                          The module allows access to all existing remote PowerShell (V1) cmdlets in addition to the 9 new, faster, and more reliable cmdlets.                                                                                                                                        
|--------------------------------------------------------------------------|
|    Old Cmdlets                    |    New/Reliable/Faster Cmdlets       |
|--------------------------------------------------------------------------|
|    Get-CASMailbox                 |    Get-EXOCASMailbox                 |
...
----------------------------------------------------------------------------

New-ExoPSSession: /home/info/.local/share/powershell/Modules/ExchangeOnlineManagement/2.0.3/ExchangeOnlineManagement.psm1:426
Line |
 426 |  … PSSession = New-ExoPSSession -ExchangeEnvironmentName $ExchangeEnviro …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
     | PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified. .

It fails because there is no way to run System.Windows.Forms on a Linux system.

Is there another way to connect to Exchange from Powershell on Linux?

Upvotes: 1

Views: 4089

Answers (1)

Clint Oliveira
Clint Oliveira

Reputation: 702

Try this (tested on Linux Kali latest build) and it worked for me:

Install-Module -Name ExchangeOnlineManagement -AllowPrerelease
$url = "https://github.com/jborean93/omi/releases/download/v1.2.0-pwsh/libmi-centos7.so"
$output = "/opt/microsoft/powershell/7/libmi.so"
Invoke-WebRequest -Uri $url -OutFile $output
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -Device

http://blog.icewolf.ch/archive/2020/09/25/exchange-online-powershell-v2-module-supports-powershell-7-and-linux.aspx

https://learn.microsoft.com/en-us/powershell/exchange/exchange-online-powershell-v2?view=exchange-ps

Upvotes: 3

Related Questions