Updated on 11 January 2019
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 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.
Once the Sign-In Assistant is installed (the machine may need to be 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. email@example.com).
$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 commands specific for user management…
To install the NuGet provide and MSOnline module, we have to enter “Y” twice. And then we can run the following to manage users in O365 via PowerShell…
Connect-MsolService -Credential $O365CREDS
You should now be able to do pretty much anything you want to your tenant via PowerShell.
- Connect to Office 365 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