Manage Office 365 with PowerShell

Download and install

Install the 64-bit version of the Microsoft Online Services Sign-In Assistant (RTW).

Run PowerShell in Admin mode and run:

Install-Module MSOnline
Install-Module -Name AzureAD

Connect

Connect to Office365 with your credentials.

Connect-MsolService

You can also use the old login prompt: Connect-MsolService -Credential $UserCredential

Test

Use something like

Get-MsolUser -EnabledFilter EnabledOnly -MaxResults 3

To test if it’s working. This should list the first three users in your Office 365 tenant.


Sources:

https://docs.microsoft.com/en-us/office365/enterprise/powershell/disable-access-to-services-while-assigning-user-licenses

https://www.blackforce.co.uk/2017/04/25/find-users-office-365-e1-license-apply-e3-via-powershell