Bulk add O365 licenses with PowerShell

The other day I had a customer that had purchased 400 EOP ATP licenses, and I need to make sure that all those users that had an E3 license also had an ATP license assigned.  After a bit of digging around, I found the correct set of PowerShell commands.  Firstly, make sure that you have your PowerShell console open and you are connected to the O365 tenant:

# Get a list of all available licenses
Get-MsolAccountSku

# Get all users with an "E" license
$users = Get-MsolUser -All | Where-Object {($_.licenses).AccountSkuId -match "ENTERPRISEPACK"}

# Assign all E licensed users an ATP license
foreach ($user in $users)
{
Set-MsolUserLicense -UserPrincipalName $user.userprincipalname -AddLicenses "domain:ATP_ENTERPRISE"
}

A very simple set of PowerShell commands that results in a hell of a lot of saved time!!