Assigning a user a role through scripting/syncing up multple user sources

We currently have two user sources that we use. One is a Database type, which we sync up with our HID access badges to allow the users to just swipe their badge for access on the floor. The other is an AD/Internal Hybrid, which the users use on their desktops and leverages our active directory. What we wanted to do is to write some scripting that will allow us to only maintain user roles in one (badge Database type), and then through scripting, assign the same roles to the user on the AD side. I wasn’t able to find the database location where the role assignments are located for the AD/Internal Hybrid, and I didn’t see any functions that allow directly assigning roles. I know I can update the SQL tables of the badge Database type, but the issue is in our organization, many of the floor people have a badge but are not in the Active Directory. Any insights would be much appreciated.