Formats SQL files.
The cmdlet formats SQL script files, either individually or in the specified folders.
Invoke-DevartFormatScript -Source <object> [-Connection <object>] [-Encoding <string>] [-FileExtension <string>] [-IncludeSubfolders <SwitchParameter>] [-Output <string>] [-Profile <string>] [<CommonParameters>]
Specifies the source SQL file or folder containing files to format.
-Source <object>
| Property | Default value |
|---|---|
| Required | True |
| Position | Named |
| Default value | - |
| Accept pipeline input | False |
| Accept wildcard characters | False |
Specifies the database connection to the server where SQL files are formatted. You can provide one of the following options:
DevartDatabaseConnectionInfo object containing connection settings.Note
A database connection is required, so the formatter can apply accurate, context‑aware SQL formatting.
-Connection <object>
| Property | Default value |
|---|---|
| Required | False |
| Position | Named |
| Default value | - |
| Accept pipeline input | False |
| Accept wildcard characters | False |
Specifies the encoding to be applied when opening and formatting the script.
-Encoding <string>
| Property | Default value |
|---|---|
| Required | False |
| Position | Named |
| Default value | - |
| Accept pipeline input | False |
| Accept wildcard characters | False |
Specifies the extension of the files to format.
-FileExtension <string>
| Property | Default value |
|---|---|
| Required | False |
| Position | Named |
| Default value | .sql |
| Accept pipeline input | False |
| Accept wildcard characters | False |
Includes the current directory and all its subdirectories in the search operation.
-IncludeSubfolders <SwitchParameter>
| Property | Default value |
|---|---|
| Required | False |
| Position | Named |
| Default value | False |
| Accept pipeline input | False |
| Accept wildcard characters | False |
Specifies the path to the file that contains formatting options. If the parameter isn’t specified, default formatting options are applied.
-Profile <string>
| Property | Default value |
|---|---|
| Required | False |
| Position | Named |
| Default value | - |
| Accept pipeline input | False |
| Accept wildcard characters | False |
Specifies the output file name or path where formatting results are saved. If the parameter isn’t specified, the results overwrite the source file or files in the source folder.
-Output <string>
| Property | Default value |
|---|---|
| Required | False |
| Position | Named |
| Default value | - |
| Accept pipeline input | False |
| Accept wildcard characters | False |
<CommonParameters>
This cmdlet supports these common parameters:
Verbose – Provides detailed output about the command operation.Debug – Provides debugging information.ErrorAction – Specifies how to respond to errors.ErrorVariable – Stores error messages in a variable.WarningAction – Specifies how to respond to warnings.WarningVariable – Stores warning messages in a variable.InformationAction – Specifies how informational messages are handled.InformationVariable – Stores informational messages in a variable.OutBuffer – Controls the number of objects buffered before output.PipelineVariable – Stores the current pipeline object in a variable.OutVariable – Stores output objects in a variable.For more information, see About Common Parameters.
System.Boolean (returns true on success and false otherwise)
System.Boolean returns:
true if the operation was successful.false if the operation failed.If the -Profile parameter isn’t specified, the active formatting profile is used. You can check which formatting profile is active in the Tools > Options > Text Editor > Formatting > Profiles.
---------- EXAMPLE 1 ----------
Invoke-DevartFormatScript -Source "D:\FormatSQL\Address.sql" -Output "D:\FormatSQL\Address_Formatted.sql"
If you want to specify a custom formatting profile, which is inactive now, you can use the -Profile parameter, entering 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, specifying the
-Profileparameter is optional. The-Profileparameter must be used only when you want to format using a custom profile that is not set as the active profile.
For information on additional command line options, see Command-line options.