Rename Availability Group and AG script
Once created an Availability Group (AG) cannot be renamed, although the databases within the AG can be renamed. You'd have to re-create it.
See here for the options for ALTERing an AG: https://msdn.microsoft.com/en-us/library/ff878601.aspx
When creating the AG using the GUI (wizard), once all the steps are completed you will see a 'Script' button which gives the option to generate a script of those steps to a new window.
You can then either save the script for later and quit the GUI, or just "finish" the wizard to actually create the AG. (The script will stay in the window)
It's a good idea to keep the script in case it needs to be re-created later (e.g. if you want to rename the AG...)


It doesn't seem to be currently possible to "Script As..." an AG in the way you would for a table or stored procedure for example.

You could also write the CREATE AVAILABILITY GROUP statement from scratch using the MSDN boilerplate code as a starting point (https://msdn.microsoft.com/en-us/library/ff878399.aspx) but that is likely to be very cumbersome and error-prone compared to using the GUI which will check you've got everything right before it lets you proceed!