Question: I am asking for a solution to execute custom SQL scripts on multiple `SQL Server Express` instances on schedule. 

Solutions that I have seen like `ApexSQL Propagate` and `Redgate SQL Multi Script` do not have a scheduler and I have more than 170 instances to run periodic jobs on them.

Any advice on how to optimally execute scheduled scripts will be deeply appreciated.

Answer: 
you can use powershell script and csv file, to automate most of your work

```
$csv = Import-Csv C:\sql\db.csv -Delimiter ";"

foreach ($line in $csv) {

    $DBServer = $line.DBServer
    $DBName = $line.DBName
    $CommandText = $line.CommandText

    $sqlConnection = New-Object System.Data.SqlClient.SqlConnection
    $sqlConnection.ConnectionString = "Data Source=$DBServer;Database=$DBName ;Integrated Security=True;"
    $sqlConnection.Open()

    $sqlCommand = New-Object System.Data.SqlClient.SqlCommand
    $sqlCommand.Connection = $sqlConnection

    $sqlCommand.CommandText = $CommandText
    $sqlCommand.ExecuteNonQuery()  
    $sqlConnection.Close()
    $sqlConnection.Dispose()       
}

```

And, sample csv file for it:

```
DBServer;DBName;CommandText
.;db;BACKUP DATABASE [db] TO  DISK = N'd:\backup\db.bak' WITH NOFORMAT, NOINIT,  NAME = N'test-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
ACER;db2;BACKUP DATABASE [db2] TO  DISK = N'd:\backup\db2.bak' WITH NOFORMAT, NOINIT,  NAME = N'test-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10

```

This script connect to server instance DBServer, in my case to default, and to db, for backup it can be master, and execute CommandText 

It use integrated security, but you can extend script to use sql server password security, you can extend script to take sql commands from file, etc, etc, etc..

You can add all your 170 instances into csv file, and script will execute sql commands against all your servers. 

Of course, for production, script must be more complicated, with error logging.
This is probably a really janky way of doing it. If you are on windows you could execute them in bat files that are run with windows scheduler. On linux you could do the same thing with cron and a bash script.