Cadzow Knowledgebase

Contact Us

Site Search

Remote Support

Print Friendly

Microsoft 365 — Connecting via PowerShell

Exchange Online

To open a PowerShell session with Exchange Online in Office 365:

  1. Run PowerShell.

  2. Enter:

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $UserCred -Authentication Basic -AllowRedirection

  3. Enter the Global Administrator credentials when prompted.

  4. Enter:

    Import-PSSession $Session -DisableNameChecking

  5. Enter the desired commands.

  6. When finished, enter:

    Remove-PSSession $Session

You can enter as many commands as required within a session, and leave a session running for a long time. If PowerShell is closed without removing the session, the session will expire by itself anyway. However, this may prevent further logins if too many sessions are left open.

To enter the credentials from the PowerShell command-line, first enter:

$UserCred=New-Object System.Management.Automation.PSCredential -ArgumentList 'username', (ConvertTo-SecureString -AsPlainText 'password' -Force)


To connect to services within Azure:

    Import-Module -Name AzureAD -Scope Local;

    $UserCred=New-Object System.Management.Automation.PSCredential -ArgumentList 'username', (ConvertTo-SecureString -AsPlainText 'password' -Force)

    Connect-AzureAD -Credential $UserCred;


Copyright © 1996-2023 Cadzow TECH Pty. Ltd. All rights reserved.
Information and prices contained in this website may change without notice. Terms of use.

Question/comment about this page? Please email