Add user to AD group and run script

We have 19 groups, say if user is added to 3 groups out of those 19. the WF should add that single user to another security group and execute the script or assign 0365 License.

can someone guide me a good approach to achieve this?