ApexSQL Enforce Command Line Interface CLI switches

Applies to
ApexSQL Enforce

Summary
This article is a guide to using CLI switches in ApexSQL Enforce.

Description

Connection switches

/serverSpecifies SQL Server connection. Server name or IP address can be used as argument
Alias: /s
Format: /server:server_name
/databaseSpecify source database name
Alias: /d
Format: /database:source_database_name
/userSpecifies the source login. Used with SQL Server authentication. If not specified, trusted connect will be used
Alias: /u
Format: /user:sourcelogin
/passwordSpecifies the source login’s password when using SQL Server authentication
Alias: /p
Format: /password:login_password
Note: /password is used only when /user switch is specified

Specific switches

/rulebaseSpecifies path to selected rulebase file
Alias: /rb
Format: /rulebase:’file_path\rulebase.axrb’
Quick tip icon

Quick tip:

To use rulebases with CLI it is mandatory to save a rule selection in the rulebasse from GUI, that will be executed on the object source. It is also advisable to set the threshold values in the Edit rulebase window

/scriptSpecifies path to selected script file
Alias: /sc
Format: /script:’file_path\script_file.sql’
Note: Script switch is used only when script rulebase is specified in /rulebase switch

Export options

/output_typeSpecifies output format
Alias: /ot
Possible arguments are:
CLI [c] – console output
XML [x] – XML export
FixSQL [f] – FixSQL export
HTML [h] – HTML report
Arguments cannot be combined
Format: /output_type:x
Note: If the switch is not specified, console output will be used
/output_nameSpecifies output path and file name
Alias: /on
Format: /output_name:
‘file_path\filename.extemsion’

Note: If not /on switch is not specified, default names will be used based on the output type: Report.xml, FixSQL.sql or Report.html
Quick tip icon

Quick tip:

With /on switch it is possible to specify only the output file name. In that case, current directory will be used as a default output destination

/output_scoreSpecifies which rule result type will be displayed in the resultset
Alias: /os
Possible arguments are:
Passed [p] – include passed results
Failed [f] – include failed results
Errors [e] – include error results
Arguments can be combined
Format: /output_score:f e
Note: If not specified, failed and error results will be displayed as default

Additional options

ApexSQL Enforce uses the standard additional options CLI switches that are found in most ApexSQL tools, with the only exception being that the /verbose switch is mandatory in ApexSQL Enforce CLI. To learn more about additional options switches, please see this article

Return codes

There are two type of return codes in ApexSQL tools: Common return codes and specific return codes. Return codes are printed using $LASTEXITCODE in PowerShell or %errorlevel% in Command prompt.

Specific return codes in ApexSQL Enforce are:

-1 for Pass – when the execution process is finished successfully and all the rules has passed
102 for Fail – when the execution process is finished successfully and the process is resulted in failure due to high impact score

Examples with common switches

Quick tip icon

Quick tip:

All shown examples assume that the current directory is the application folder. If it’s not, the full path to ApexSQLEnforce.com must be specified

Processing Sample_RB rulebase on AdventureworksDW2016CTP3 database located on P3TAR\MSSQLSERVER2017 server with trusted authentication and creating FixSQL file Fix.sql

ApexSQLEnforce.com /s:P3TAR\MSSQLSERVER2017 /d:AdventureworksDW2016CTP3 /rb:’D:\ApexSQL Enforce rulebases\Sample_RB.axrb’ /ot:f /on:’D:results\Fix.sql’ /v

Processing Sample_RB rulebase on AdventureworksDW2016CTP3 database that is located on P3TAR\MSSQLSERVER2017 server using “sa” as user and “admin” as password and outputting console output into a process.txt file that will be generated in D:\results folder

ApexSQLEnforce.com /s: P3TAR\MSSQLSERVER2017 /d:AdventureworksDW2016CTP3 /u:sa /p:admin /rb:’d:\ApexSQL Enforce rulebases\Sample_RB.axrb’ /ot:c /out:’D:\results\process.txt’ /v

Quick tip icon

Quick tip:

Output destination must be set to an existing folder. ApexSQL Enforce CLI switches will not create a folder if it is missing

Processing Script_RB rulebase on a database script aw2016.sql, creating HTML report including only failed results and overwriting existing file with the same name.

ApexSQLEnforce.com /s: P3TAR\MSSQLSERVER2017 /d:AdventureworksDW2016CTP3 /sc:’E:\Desktop\aw2016.sql’ /rb:’D:\ApexSQL Enforce rulebases\Script_RB.axrb’ /os:f /ot:html /on:’D:results\Results.html’ /v /f