So you have Azure AD Connect that does the sync for you. Sync cycle by default starts every 30 minutes. Then the selected objects (based on some config) are synced to Azure AD which is the identity provider for all MS cloud services.
What you need to do is to create a user group, sync this group to Azure AD and place your user accounts in our onprem AD to this group. And in Azure AD, configure Group Based licensing (the provided by JulienGoindin-666), so all users that are members of the group get selected licenses automatically. This is the recommended way, don't do any magic with PowerShell :-)