Sometimes it’s difficult to find the simplest things because they are buried in other data. Here are two commands that do just one thing–get you connected to your Office 365 account in the cloud.
Connect to Office 365/MSOL
Prerequisites:
- Install the 64-bit version of the Microsoft Online Services Sign-in Assistant: Microsoft Online Services Sign-in Assistant for IT Professionals RTW.
- Install the 64-bit version of the Windows Azure Active Directory Module for Windows PowerShell: Windows Azure Active Directory Module for Windows PowerShell (64-bit version).
Open the PowerShell ISE with Run as Administrator on your computer. Type in the code below. Run the code and enter your O365 user name and password and you’re connected.
$UserCredential = Get-Credential Connect-MsolService -Credential $UserCredential
Connect to Office 365/Exchange
Open the PowerShell ISE with Run as Administrator on your computer. Type in the code below. Run the code and enter your O365 user name and password. You will be connected to an Office 365 Exchange session.
$cred = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred -Authentication Basic –AllowRedirection Import-PSSession $Session
Disconnect from Office 365/Exchange
It’s a good practice to remember to disconnect from your O365 Exchange session when you’re done. Type the code below into your PowerShell session and you will be disconnected.
Remove-PSSession $Session
Now you can add these snippets to any script you create to work in your tenant. How easy was that?