Firstly a disclaimer this has only been tested in a development environment where the databases were hardly used.
This was done on SQL Server 2014 SP2 but could well work with other editions.
I do not recommend you try this in production unless you have fully tested and are satisfied with the outcome. With that being said here is the process that can be used to reinstall a version of SQL and keep your availablity groups synchronized, and all other settings intact.
- Move any primary Availability groups to another node.
- Stop SQL Server (via SQL Server configuration Manager
- Copy all system databases (and log files) to a backup directory (primarily master, model and msdb)
- Uninstall SQL Server after ensuring you are fully backed up of course
- Reboot the box you are working on, regardless of whether or not you are prompted to.
- Reinstall SQL with the same directories, collation etc as was originally used. You can go to the latest service pack or CU if you wish to at this stage.
- Reenable availability groups in SQL Configuration Manager
- Restart SQL (this may be unnecesary)
- Stop SQL
- Copy and replace the system databases and log files that you backed up earlier.
- Restart SQL Server Test thoroughly