Invoke-DevartFormatScript

Last modified: March 28, 2025

Synopsis

Formats SQL files.

Description

The cmdlet allows you to format multiple SQL script files or even folders with SQL script files.

Syntax

Invoke-DevartFormatScript -Source <object> [-Connection <object>] [-Encoding <string>] [-FileExtension <string>] [-IncludeSubfolders <SwitchParameter>] [-Output <string>] [-Profile <string>] [<CommonParameters>]

Parameters

-Source <object>

Specifies the source SQL file or a folder with the files to be formatted.

Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false

-Connection <object>

The DevartDatabaseConnectionInfo or connection string.

Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false

-Encoding <string>

Specifies the encoding which should be applied to open and save files.

Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false

-FileExtension <string>

Specifies the extension of the sourcefolder files that will be formatted.

The .sql extension is chosen by default.

Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false

-IncludeSubfolders <SwitchParameter>

Include the current directory and all subdirectories in search operation.

Required? false

Position? named

Default value false

Accept pipeline input? false

Accept wildcard characters? false

-Profile <string>

Specifies the path to file that contains formatting options settings.

If the parameter is not specified, default formatting options settings will be applied.

Required? false

Position? named

Derfault value

Accept pipeline input? false

Accept wildcard characters? false

-Output <string>

Specifies the output file or path name where formatting results will be saved.

If the parameter is not specified, the formatting results will be saved in the source file or folder.

Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false

<CommonParameters>

This cmdlet supports the following common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, InformationAction, InformationVariable, OutBuffer, PipelineVariable, and OutVariable. For more information, see About CommonParameters.

Outputs

System.Boolean (returns true on success and false otherwise)

Examples

Example 1: If the -Profile parameter is not specified, the active formatting profile is used. You can check which formatting profile is active in the Options dialog under Text Editor > Formatting > Profiles.

---------- EXAMPLE 1 ----------
Invoke-DevartFormatScript -Source "D:\FormatSQL\Address.sql" -Output "D:\FormatSQL\Address_Formatted.sql"

Example 2: If you want to specify a custom formatting profile, which is inactive now, you can use the -Profile parameter, specifying the full path to the profile and the file name.

---------- EXAMPLE 2 ----------
Invoke-DevartFormatScript -Source "D:\FormatSQL\Address.sql -Output D:\FormatSQL\Address_Formatted.sql" -Profile "C:\Users\Username\AppData\Roaming\Devart\dbForge Studio for SQL Server\FormatProfiles\CustomProfile.xml"

Note

If a custom formatting profile is active, it is not necessary to specify the -Profile parameter. The -Profile parameter must be used only when you need to format using a custom profile that is not currently set as active.

See Formatting using the command line for information on additional command line options.