olahallengren / sql-server-maintenance-solution

SQL Server Maintenance Solution
https://ola.hallengren.com
MIT License
2.91k stars 756 forks source link

Add an option to generate the Task Scheduler commands for SQL Express #796

Open mdell-seradex opened 9 months ago

mdell-seradex commented 9 months ago

The current script can create SQL Agent Jobs that execute T-SQL commands. It first creates them in an @Jobs table variable, and then creates the Jobs from that data. It would be nice if, for SQL Express, it could generate (or update) the .cmd or .bat script files, from those commands. It would be even better if it created powershell commands to create Task Scheduler tasks for those. This would also allow your maintenance script to control the default timing of the commands.

It would also be nice if we could choose to combine commands into groups such that the commands in a group would be executed sequentially, but that is probably asking for too much. If this were to be added, then naming may become an issue.

I setup these commands for an instance of SQL Express just recently. To do this, I manually adjusted the primary script to create the data in the @Jobs table variable, and then pushed it into a real table. I next proceeded to use that data to manually create the batch files and Task Scheduler steps. I found that this was easier to do, instead of trying to read through all the documentation and create those commands myself.

It may have been even simpler had I created stored procedures to run the command batches. That is an approach that could be taken, and may make updating them simpler.

Thank you, Mark