As part of our free SDU Tools for developers and DBAs, we have many scripting functions. SQL Server allows you to create your own server roles, and generally, you should do this instead of using the fixed server roles, as it lets you allocate just the required permissions. To allow scripting these out, we've added a tool called ScriptUserDefinedServerRoles .
It's a function and doesn't require any parameters.
You can use our tools as a set or as a great example of how to write functions like these.
You can see it in action in the main image above, and in the video here:
Access to SDU Tools is one of the benefits of being an SDU Insider, along with access to our other free tools and eBooks. Please just visit here for more info: