How to connect to Exchange Online PowerShell.

The main reason you will want to connect to Exchange Online PowerShell is to run specific commands to change attributes and enable/disable services.

So how to connect, first of all you have to run powershell on a Windows 10/11 pc as administrator.

After you reach the powershell command line the commands needed are as follows.

Install Exchange Online PowerShell V2 module

Before we can install Exchange Online PowerShell V2 module, we need to set up the system.

Configure PowerShell to install scripts

By default, we can’t install scripts. To require all PowerShell scripts that you download from the internet are signed by a trusted publisher, run PowerShell as administrator, and run the Set-ExecutionPolicy RemoteSigned cmdlet. Press Y and press Enter.

PS C:\> Set-ExecutionPolicy RemoteSigned

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
http://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y

Important: Close and re-open the elevated Windows PowerShell window to have the changes apply.

Install PowerShellGet module

Run PowerShell as administrator. Run the Install-Module PowershellGet -Force cmdlet. When asked to install NuGet provider, press Y and follow with Enter.

PS C:\> Install-Module PowershellGet -Force

NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\administrator.EXOIP\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install
and import the NuGet provider now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Y

If you get an error that it’s unable to install, read the article Unable to install NuGet provider for PowerShell.

Important: Close and re-open the elevated Windows PowerShell window to have the changes apply.

Install Exchange Online Management module

Install the Exchange Online Management module. Press Y and Enter.

PS C:\> Install-Module -Name ExchangeOnlineManagement

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y

Connect to Exchange Online PowerShell

Connect with your admin account to Exchange Online. Run the Connect-ExchangeOnline cmdlet.

PS C:\> Connect-ExchangeOnline -UserPrincipalName admin@test.com

In the sign-in window that opens, enter your password, and then click Sign in. Replace admin@test.com with an admin account for your Tenant.

If MFA is enabled, a verification code is generated and delivered based on the verification response option that’s configured for your account. For example, a text message or the Azure Authenticator app on your mobile phone.

After the verification succeeds, you will get back to the PowerShell window.

Verify Exchange Online PowerShell connection

Run the Get-EXOMailbox cmdlet. You will see a list of all the mailboxes in Office 365.

PS C:\> Get-EXOMailbox | ft UserPrincipalName,DisplayName

UserPrincipalName        DisplayName
-----------------        -----------
test1@test.com           Test1
test2@test.com           Test2

Disconnect Exchange Online

Be sure to disconnect the remote PowerShell session when you’re finished. If you close the Exchange Online PowerShell Module window without disconnecting the session, you could use up all the remote PowerShell sessions available to you, and you’ll need to wait for the sessions to expire.

Run the Disconnect-ExchangeOnline cmdlet to disconnect the remote PowerShell session.

PS C:\> Disconnect-ExchangeOnline

That’s it!

Enable SMTP Auth for the Tenant or a specific user

Use the following commands before disconnecting

get-CASMailbox -Identity USEREMAILADDRESS | fl SmtpClientAuthenticationDisabled

Set-CASMailbox -Identity USEREMAILADDRESS -SmtpClientAuthenticationDisabled $false

Global
Set-TransportConfig –SmtpClientAuthenticationDisabled $false

Enable auto expanding Archive, may require additional licensing

Use the following commands before disconnecting

Auto expanding Archive Setting
Whole Organization

Set-OrganizationConfig -AutoExpandingArchive

Per User

Enable-Mailbox <user mailbox> -AutoExpandingArchive