:CONNECT SQL2K16-AGL1

CREATE AVAILABILITY GROUP [SQL2K16-DAG]  
   WITH (DISTRIBUTED)   
   AVAILABILITY GROUP ON  
      'SQL2K16-AG1' WITH    
      (   
         LISTENER_URL = 'tcp://SQL2K16-AGL1:5022',    
         AVAILABILITY_MODE = ASYNCHRONOUS_COMMIT,   
         FAILOVER_MODE = MANUAL,   
         SEEDING_MODE = AUTOMATIC   
      ),   
      'SQL2K16-AG2' WITH    
      (   
         LISTENER_URL = 'tcp://SQL2K16-AGL2:5022',   
         AVAILABILITY_MODE = ASYNCHRONOUS_COMMIT,   
         FAILOVER_MODE = MANUAL,   
         SEEDING_MODE = AUTOMATIC   
      );    
GO   

:CONNECT SQL2K16-AGL2
ALTER AVAILABILITY GROUP [SQL2K16-DAG]   
   JOIN   
   AVAILABILITY GROUP ON  
      'SQL2K16-AG1' WITH    
      (   
         LISTENER_URL = 'tcp://SQL2K16-AGL1:5022',    
         AVAILABILITY_MODE = ASYNCHRONOUS_COMMIT,   
         FAILOVER_MODE = MANUAL,   
         SEEDING_MODE = AUTOMATIC   
      ),   
      'SQL2K16-AG2' WITH    
      (   
         LISTENER_URL = 'tcp://SQL2K16-AGL2:5022',   
         AVAILABILITY_MODE = ASYNCHRONOUS_COMMIT,   
         FAILOVER_MODE = MANUAL,   
         SEEDING_MODE = AUTOMATIC   
      );  
GO  