Invoke-DevartFormatScript

Synopsis

Formats SQL files.

Description

The cmdlet formats SQL script files, either individually or in the specified folders.

Syntax

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

Parameters

-Source

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

-Connection

Specifies the database connection to the server where SQL files are formatted. You can provide one of the following options:

  • A DevartDatabaseConnectionInfo object containing connection settings.
  • A connection string that defines how to connect to the database.

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

-Encoding

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

-FileExtension

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

-IncludeSubfolders

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

-Profile

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

-Output

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

Common parameters

<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.

Output

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

System.Boolean returns:

  • true if the operation was successful.
  • false if the operation failed.

Examples

Example 1

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"

Example 2

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 -Profile parameter is optional. The -Profile parameter must be used only when you want to format using a custom profile that is not set as the active profile.

Related links

For information on additional command line options, see Command-line options.