SQL Server: Programatically trigger export of db schema
These days, by far the best way is both open source and from Microsoft (what a world we live in):

mssql-scripter

The README says it all, so I'll just quote it:


  mssql-scripter is the multiplatform command line equivalent of the
  widely used Generate Scripts Wizard experience in SSMS. You can use
  mssql-scripter on Linux, macOS, and Windows to generate data
  definition language (DDL) and data manipulation language (DML) T-SQL
  scripts for database objects in SQL Server running anywhere, Azure SQL
  Database, and Azure SQL Data Warehouse. You can save the generated
  T-SQL script to a .sql file or pipe it to standard nix utilities (for
  example, sed, awk, grep) for further transformations. You can edit the
  generated script or check it into source control and subsequently
  execute the script in your existing SQL database deployment processes
  and DevOps pipelines with standard multiplatform SQL command line
  tools such as sqlcmd.