Update 2019-06-16 I recently learned that Office 365 licensing can be managed via Azure Active Directory’s group based licensing feature and I have since switched to using this and have retired this script. I’ll leave this post and the script itself available here, on the Microsoft TechNet Gallery and GitHub, but I’ll not be developing the script any further. For more information on Azure Active Directory group-based licensing please check out Microsoft’s documentation here and here to start with.
Update 2018-11-04: I’ve evolved the script in this post into a more friendly utility which I’ve posted about here. If you are familiar with my other PowerShell scripts/utilities this isn’t as complete or polished as them, but it get’s the job done, and that’s all we can really ask for right? Let’s say it’s in early beta. The purpose of this script is to automate the process of setting the location and Office 365 license for users, using a local Active Directory to specify the users.