Updated on 19 September 2016
To connect to and manage Office 365 with the Azure AD Module for PowerShell, there are two prerequisites needed.
NOTE: If planning to run the tasks from an Exchange server, the MSOL commands (i.e. Connect-MsolService) may not work. If this is the case, install the two tools on and run the commands from an admin workstation.
NOTE: Make sure you select the proper version of each tool for the machine they are being installed on. As of 20 October 2014, only the 64-bit versions are available.
NOTE: A restart of the machine may be required after installing the Sign-In Assistant. But it will not hurt to install the Azure AD Module before restarting.
- Microsoft Online Services Sign-In Assistant for IT Professionals RTW
- Azure Active Directory Module for Windows PowerShell
Once both tools are installed (and the machine has been restarted), open an elevated Active Directory Module for Windows PowerShell console (not Windows PowerShell) and enter the following commands to connect to Office 365. This first command may be required if you haven’t already set the execution policy level on the machine we are using to connect to O365…
Set-ExecutionPolicy Unrestricted -Force
This command will pop up the window required for you to enter your Office 365 credentials. In the login pop-up, enter Office 365 global admin credentials to proceed. The user name must be entered as a fully qualified name (i.e. firstname.lastname@example.org).
$O365CREDS = Get-Credential
$SESSION = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $O365CREDS -Authentication Basic -AllowRedirection
This command brings that cloud-based PowerShell session to the local computer…
Lastly, we will download the O365 specific commands to be run locally…
Connect-MsolService -Credential $O365CREDS
You should now be able to do pretty much anything you want to your tenant via PowerShell.
- Connect Windows PowerShell to the Service
- How To Connect to Office 365 Through PowerShell
- Install-PowerShellOptions.ps1 – Script to deploy and connect to on premises and cloud Microsoft services
- Connect-EXO.ps1 – Connect to Exchange Online using remote PowerShell
- Connect to Office 365 and Exchange Online using a Script
- PowerShell Function to Connect to Office 365 Exchange Online
Originally published on 21 March 2013 at http://oddytee.blogspot.com/2013/03/connect-to-office-365-with-powershell.html