Depending on business needs, technical requirements, or both, directory synchronization (aka DirSync) is the most common provisioning choice for enterprise customers who are moving to Office 365. DirSync allows identities to be mastered on-premises and all updates to that identity are synchronized to the Office 365 AD.
Currently DirSync syncs identities with Office 365 but does not offer the ability to configure business logic and assign licenses to synced users.
While we wait for a long-term solution to help automate license assignment for customers we have published a PowerShell-based solution that enables customers to apply their business logic to automate license assignment. This solution allows administrators to assign licenses to users based on the following:
1. Attribute value matching (i.e. “all users with UPN containing @legal.contoso.com”)
2. Group membership
Read more in this article “How to use PowerShell to Automatically Assign Licenses to your Office365 Users“