Powershell – List and Assign Office 365 Licenses

Microsoft are adding more and more functionality for administrators in Office 365 – Unfortunately, there is still no ‘easy’ and quick way to assign a new license, in bulk, to a lot of existing¬†users. Specifically, the OFFICESUBSCRIPTION_STUDENT that was introduced to provide Office 365 licenses to Students was the one I was looking for.

Below are some quick Powershell commands to get you started (assuming that you know how to connect to Office 365 Exchange Online via Powershell)

List SKUs / Licenses Available
This will list your organisation before the SKU name, e.g. YOUR_ORG:OFFICESUBSCRIPTION_STUDENT

Get-MsolAccountSku

Add Single License to User
You can pipe this | with Get-MsolUser to set the license on a single user.

Set-MsolUserLicense -AddLicenses YOUR_ORG:OFFICESUBSCRIPTION_STUDENT

Bulk Add by Domain Name
If you have multiple domains, or sub-domains you can assign licenses in bulk easily. Replace the ‘your org’ strings below to match your setup though.

Get-MsolUser -DomainName staff.yourorg.com -All | Set-MsolUserLicense -AddLicenses YOUR_ORG:OFFICESUBSCRIPTION_STUDENT

You can use multiple filters on the last command and just pipe the second command using the |. This could be by name, by group or domain as show above.

Powershell – Update Active Directory Users Profile Data

Here is a small snippet to bulk update an OU with user profile data. Recently used to fill in default values for AD.

Change the OU and Domain details to suit; Requires full LDAP path (e.g. YOURDOMAIN.LOCAL would be DC=YOURDOM,DC=LOCAL)

Import-Module ActiveDirectory 
$Users = Get-ADUser -Filter * -SearchBase "OU=Users,DC=YOURDOM,DC=LOCAL"

foreach($User in $Users) {
    # Update properties.
    $User.postalAddress = "Address Line 1"
	$User.street = "Address Line 2"
	$User.telephoneNumber = "00000 00000000"
	$User.department = "Your Department"
	$User.wWWHomePage = "www.website.com"
	$User.postOfficeBox = "England"
	$User.city = "City"
	$User.state = "County"
	$User.postalCode = "Post Code"
	
    Set-ADUser -Instance $User
}

Always be careful bulk updating users via script. More profile values can be found in the Advanced Attribute Editor in the Active Directory Snap-In.