Save project as automation script

Applies to
Several ApexSQL products including ApexSQL Build, ApexSQL Compare, ApexSQL Data Diff, ApexSQL Diff, ApexSQL Diff for MySQL, ApexSQL Doc, ApexSQL Doc for MySQL, ApexSQL Enforce, ApexSQL Generate, ApexSQL Log, ApexSQL Script and ApexSQL Trigger

Summary
This article explains all about the Save project as automation script feature.

Description

Most ApexSQL tools have a CLI switch to consuming a project file. This allows for the simplicity and ease of using a project file but also for unattended automation of a batch file or a PowerShell script. A batch file can be manually initiated simply by double-clicking, or it can be scheduled via SQL Server job, PowerShell project, etc., as a part of the automating process.

But, some users prefer the transparency and full granular control of explicitly setting all of the switches directly using the CLI, without using the project file to import switch values. That is where the Save project as automation script serves a purpose. Save project as automation script is a feature that allows creating batch files and PowerShell scripts automatically, based on the selected settings in the application GUI.

Depending on the application, the Save project as automation script feature is located in the final wizard step as in the following examples:

  • ApexSQL Data Diff, ApexSQL Diff and ApexSQL Diff for MySQL – Synchronization wizard

  • ApexSQL Log – Output wizard

  • ApexSQL Script – Script wizard

It can also be located, under the Save button, from the Home tab in the main application window, as shown in this example with ApexSQL Generate:

Once the feature is initiated, the Automation script window will be shown and all previously set options will be expressed through their corresponding CLI switches:

By default, Batch script is selected, but if PowerShell is preferred just select it and a preview of the PowerShell script will be shown:

Additionally, instead of having an individual CLI switch for each option, the Project file option can be checked and saved, and it will replace all CLI switches, except for the output and additional option switches:

Output types

All mentioned applications have an option to set different output types e.g. a synchronization SQL script, reports, or executable package. Output types are located on the top of the Automation script window:

Each output type has the Browse or Settings button next to it, which can be used to set the output type’s location or some additional options, as an individual CLI switch in an automation script.

For example, a Sync script is set as the primary output type, the Browse button is clicked and a path is provided. CSV is used as the secondary output type, the Settings button is clicked and the below options are checked:

Once the desired export options are set and the Save button is clicked, the Browse for folder window will appear and it will allow setting the CSV folder location:

After saving the folder location, all previously set options will be shown in the Script panel:

Additional options

All additional options that are part of the CLI, such as verbose mode, can be added to a batch or PowerShell script simply by checking them in the Automation script window.

Explanation of additional options:

  • Redirect console output to file – console output can be redirected to a file in a specified location

  • Verbose – shows all messages about processed action

  • Force – overwrites an existing output file(s) with the same name

  • Disable echo – turns the echoing option on or off, or displays a message

  • Return code – provides one of the return codes upon the batch file or PowerShell script execution

After going through all the options and setting everything up, click the Save button

Q: Can I save the project file without closing the Automation script window?

A: Yes. If any change is made during the editing of the existing project, it can be saved with a click on the Save button next to the project file field:

Q: Is it possible to override some options that are “hard-coded” in a project file?

A: Yes. By adding a CLI switch that is already covered with some option in a project file, a CLI switch will override the option set in a project file.