dbatools is a free PowerShell module with over 300 SQL Server administration, best practice and migration commands included.

Please note that documentation and command names may be out of date while we work furiously towards 1.0


Creates a new Microsoft.SqlServer.Management.Smo.ScriptingOptions object. Basically saves you the time from remembering the SMO 😉

See MSDN for more information.



To export Agent Jobs with the Scripting Options ScriptDrops set to $false and WithDependencies set to true.

$options = New-DbaScriptingOption
$options.ScriptDrops = $false
$options.WithDependencies = $true
Get-DbaAgentJob -SqlInstance sql2016 | Export-DbaScript -ScriptingOptionObject $options


From PowerShell, execute Get-Help New-DbaScriptingOption -Detailed for more information on this function.

Source Code

Want to see the source code? View New-DbaScriptingOption.ps1 on GitHub

Related commands