You can do this with the Active Roles Synchronization Service Back Sync.
If you prefer to script it, you will need to set the edsvaAzureOffice365Enabled boolean to TRUE and the edsvaAzureObjectID will need to be populated with the objectID of the corresponding Azure Group.