What’s not working? Are you getting an error? You need to make sure you refresh the identity with the option enabled to “Refresh assigned, detected roles and promote additional entitlements”.
Also, instead of using a script, I would use a Match List to make it easier to implement and review for business role owners. You can select an Application and target a specific value if you need to ensure the account is enabled before the role is assigned.