Manage Office365 with PowerShell

Installation and setup

Install the 64-bit version of the Microsoft Online Services Sign-In Assistant for IT Professionals RTW:

Open an administrator-level PowerShell command prompt.

Install-Module MSOnline

Connect to Office365 with credentials

You can also use the old login prompt: $UserCredential = Get-Credential

Connect-MsolService
Connect-MsolService -Credential $UserCredential

Example commands

List all users with E3 lisence

Get-MsolUser -All | where {$_.isLicensed -eq "TRUE" -and $_.Licenses.AccountSKUID -eq "tenantname:ENTERPRISEPACK"}

List all users without an MFA (STANDALONE) License

Get-MsolUser -All | where {$_.Licenses.AccountSKUID -eq "tenantname:MFA_STANDALONE"}

Remove E1 license from specific user

Set-MsolUserLicense -UserPrincipalName example@example.com -RemoveLicenses "tenantname:STANDARDPACK"

View all services within a license for a user:

Get-MsolUser -UserPrincipalName example@example.com | Select-Object -ExpandProperty Licenses | Select-Object -ExpandProperty ServiceStatus

Manually update Azure AD and Office365 on the server

Start-ADSyncSyncCycle -PolicyType delta

To disable Teams for all users with an active license for your named plan, run the following command:

Get-MsolUser | Where-Object {$_.licenses[0].AccountSku.SkuPartNumber -eq  ($acctSKU).Substring($acctSKU.IndexOf(":")+1,  $acctSKU.Length-$acctSKU.IndexOf(":")-1) -and $_.IsLicensed -eq $True} |  Set-MsolUserLicense -LicenseOptions $x

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