Before you can connect to Office 365 you first need to install the required modules. Unfortunately, Microsoft is now recommending you install two modules to manage Office 365. Here are the two modules we will be installing.
- Installing Module 1 (Microsoft Azure Active Directory Module for Windows PowerShell)
-
Open PowerShell as administrator. To do this right-click on PowerShell and choose “run as administrator”
-
Type the following command and press enter
Install-module -name MSOnline
Note: If you get a message about NuGet version 2.8.5.201 or newer click yes or type Y. If you get a message about installing the module from an untrusted repository click yes or type Y.
-
Type the command below to list the installed modules
Get-Module -ListAvailable
Link a PIC
- Installing Module 2 (Azure Active Directory PowerShell for Graph)
-
Open PowerShell as Administrator
-
Type the following command and press enter
Install-Module -Name AzureAD
-
Verify the module is installed
get-module -ListAvailable
Each module has different commands for connecting to office 365. You don’t have to use both, you can pick which module you want to use.
- Connect with Module 1 (Microsoft Azure Active Directory Module for Windows PowerShell… AKA MSOnline)
-
Type the following command and press enter
Connect-MsolService
Note: You will get prompted to sign in.
Link a PIC
- Verify connection
Get-MsolCompanyInformation
the command below to verify I’m connected to Office 365.
- Connect with Module 2 (Azure Active Directory PowerShell for Graph)
-
Type the following command and press enter
Connect-AzureAD
The AzureAD module will automatically display some company information when it connects.
Link a PIC
Here are a few examples of using PowerShell to manage office 365
- Get all Office 365 Users
Get-MsolUser -All | select-object *
- Get all licensed users
Get-MsolUser -All | Where-Object { $_.isLicensed -eq "TRUE" }
- Get Azure devices
Get-AzureADDevice
- Set a users password
Set-MsolUserPassword-UserPrincipalName “<email address>” -NewPassword “New Password”
- Assign a license to a user
Set-MsolUserLicense -UserPrincipalName “user name” -AddLicenses “<licensed name>”