How to connect to Office 365 from Powershell

Below you will find the necessary commands to connect to Office 365.

Required software:

Connect to the 365 system with:

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 -AllowClobber
Connect-MsolService -Credential $O365Cred

Note: if you have Windows 10 (please start powershell as Administrator, otherwise it won’t work), then you will have to use this code:

$O365Cred = Get-Credential
$O365Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $O365Cred -Authentication Basic -AllowRedirection
Import-PSSession $O365Session -AllowClobber

 

 

Leave a Reply

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

*