---
title: "New-DbaScriptingOption"
description: "Creates a customizable SMO ScriptingOptions object for controlling T-SQL script generation"
url: "https://dbatools.io/New-DbaScriptingOption/"
availability: "Windows, Linux, macOS"
tags: ["General", "Script", "Object"]
author: "Chrissy LeMaire (@cl), netnerds.net"
source: "https://github.com/dataplat/dbatools/blob/master/public/New-DbaScriptingOption.ps1"
last_updated: "2024-01-01"
---

# New-DbaScriptingOption

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

```powershell
New-DbaScriptingOption
    [<CommonParameters>]

```

## Examples

### Example 1: Exports Agent Jobs with the Scripting Options ScriptDrops/WithDependencies set to $false and...

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

---

Part of [dbatools](https://dbatools.io/), a free and open source PowerShell module for SQL Server administration. Full command index: https://dbatools.io/commands/
