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.
- 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.
- Install the downloaded software on your local machine.
Connect to Office 365 / Exchange Online
- Open the Windows PowerShell.
- Execute the follwoing command if the Microsoft Online Services Sign-in Assistant has been installed:
Import-Module MSOnline
- Execute the following command
$LiveCred = Get-Credential
and enter the admin credentials in the popup dialog. - Execute the following commands:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
Import-PSSession $Session - 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.
- 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