SQL Server: Programatically trigger export of db schema SQL Server 2014, Std edition

We have seen and used, over the years, a variety of sprocs and non-MS tools to export the DB schema.

The way we really like to do this is the built in utility, in SSMS, as described here on SO: https://stackoverflow.com/a/12036513/147637

We strongly prefer the MS tool, because it is more complete than hand-rolled tools, and provides super clean, properly organized and structured output.

However, we want to automate this.

How can the MS engine be driven programatically?
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.