Use PowerShell to Connect Exchange Online in Office 365

Connect to Office 365 / Exchange Online


    1. Open the Windows PowerShell.
    1. Execute the follwoing command if the Microsoft Online Services Sign-in Assistant has been installed: Import-Module MSOnline
    1. Execute the following command $Cred = Get-Credential and enter the admin credentials in the popup dialog.
    1. Execute the following commands:
      $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $Cred -Authentication Basic -AllowRedirection
      Import-PSSession $Session
  1. You are connected now. If the Microsoft Online Services Sign-in Assistant has been installed, execute the following command:
    Connect-MsolService –Credential $Cred


Enter credentials without popup dialog

You can enter the credentials directly in the script without using a popup dialog. This method may be used to automate PowerShell commands.

  1. Use the following commands instead of $Cred = Get-Credential and replace the credentials:
    $Username = ""
    $Password = ConvertTo-SecureString ‘YourPassword’ -AsPlainText -Force
    $Cred = New-Object System.Management.Automation.PSCredential $Username, $Password



Leave a Reply

Your email address will not be published. Required fields are marked *