How to connect to Office 365 from powershell

MS Outlook & Exchange sucks but that's what my company supports. I am not going to discuss why I need it this... it will end up in an unnecessary flame.

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 *