Thor Logo dbatools

New-DbaScriptingOption

View Source
Chrissy LeMaire (@cl), netnerds.net
Windows, Linux, macOS

Synopsis

Creates a customizable SMO ScriptingOptions object for controlling T-SQL script generation

Description

Creates a Microsoft.SqlServer.Management.Smo.ScriptingOptions object that controls how SQL Server objects get scripted into T-SQL CREATE statements. This object lets you customize what gets included when using Export-DbaScript and other dbatools scripting commands - things like whether to include indexes, triggers, permissions, dependencies, or batch separators. Perfect for creating deployment scripts where you need specific control over what gets scripted and how it’s formatted.

See https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.scriptingoptions.aspx for more information

Syntax

New-DbaScriptingOption
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> $options = New-DbaScriptingOption
PS C:\> $options.ScriptDrops = $false
PS C:\> $options.WithDependencies = $false
PS C:\> $options.AgentAlertJob = $true
PS C:\> $options.AgentNotify = $true
PS C:\> Get-DbaAgentJob -SqlInstance sql2016 | Export-DbaScript -ScriptingOptionObject $options

Exports Agent Jobs with the Scripting Options ScriptDrops/WithDependencies set to $false and AgentAlertJob/AgentNotify set to true

Outputs

Microsoft.SqlServer.Management.Smo.ScriptingOptions

Returns a single ScriptingOptions object that can be used to customize script generation behavior. This object contains dozens of boolean and string properties that control what gets included when scripting SQL Server objects (indexes, triggers, permissions, dependencies, batch separators, etc.). Use this object with Export-DbaScript and other scripting commands to control the generated T-SQL output.

Common properties include:

  • ScriptDrops: Include DROP statements (Boolean)
  • WithDependencies: Include dependent objects (Boolean)
  • AgentAlertJob: Include SQL Agent Alert and Job information (Boolean)
  • AgentNotify: Include SQL Agent notification (Boolean)
  • Indexes: Include indexes (Boolean)
  • Triggers: Include triggers (Boolean)
  • Permissions: Include permissions (Boolean)
  • TargetServerVersion: Target SQL Server version for compatibility See Microsoft.SqlServer.Management.Smo.ScriptingOptions documentation for complete property list.