You can add and update roles through the ManagementServer.RoleFolder property: https://doc.developer.milestonesys.com/html/index.html?base=miphelp/class_video_o_s_1_1_platform_1_1_configuration_items_1_1_management_server.html&tree=tree_search.html?search=managementserver
Have a look at the following example to see how to generally work with these classes: https://doc.developer.milestonesys.com/html/index.html?base=samples/componentsamples/configaddcameras/readme.html&tree=tree_2.html