Connect to Office 365 / Exchange Online

Sharing is caring!

 

The Windows PowerShell cmdlets for Office 365 management and deployment have to be installed on your local machine, if you want to manage e.g. Office 365 licences.

  1. Download the appropriate version of the Microsoft Online Services Sign-in Assistant depending on your operating system version: http://technet.microsoft.com/en-us/library/hh974317.aspx.
  2. Install the downloaded software on your local machine.

 

 Connect to Office 365 / Exchange Online

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

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 $LiveCred = Get-Credential and replace the credentials:
    $Username = "admin@yourdomain.edu"
    $Password = ConvertTo-SecureString ‘YourPassword’ -AsPlainText -Force
    $LiveCred = New-Object System.Management.Automation.PSCredential $Username, $Password  

Can write Following code in powershell to establish connection 


Set-ExecutionPolicy Unrestricted
Import-Module MSOnline
$O365Cred = Get-Credential
$O365Session = New-PSSession –ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $O365Cred -Authentication Basic -AllowRedirection
Import-PSSession $O365Session
Connect-MsolService –Credential $O365Cred
 

    Leave a Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.