Thor Logo dbatools

Get-DbaInstanceUserOption

View Source
Klaas Vandenberghe (@powerdbaklaas)
Windows, Linux, macOS

Synopsis

Retrieves instance-level user option defaults that affect new database connections

Description

Returns the default user options configured at the SQL Server instance level that are automatically applied to new database connections. These settings include ANSI compliance options like ANSI_NULLS, QUOTED_IDENTIFIER, date format preferences, and other connection-level defaults. This is useful when standardizing connection behavior across environments or troubleshooting why applications behave differently on different instances. Unlike Get-DbaDbccUserOption which shows current session settings, this command shows the instance defaults that would be inherited by new connections.

Syntax

Get-DbaInstanceUserOption
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Get-DbaInstanceUserOption -SqlInstance localhost

Returns SQL Instance user options on the local default SQL Server instance

Example: 2
PS C:\> Get-DbaInstanceUserOption -SqlInstance sql2, sql4\sqlexpress

Returns SQL Instance user options on default instance on sql2 and sqlexpress instance on sql4

Example: 3
PS C:\> 'sql2','sql4' | Get-DbaInstanceUserOption

Returns SQL Instance user options on sql2 and sql4

Required Parameters

-SqlInstance

The target SQL Server instance or instances.
This can be a collection and receive pipeline input to allow the function to be executed against multiple SQL Server instances.

PropertyValue
Alias
RequiredTrue
Pipelinetrue (ByValue)
Default Value

Optional Parameters

-SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with “sea of red” exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this “nice by default” feature off and enables you to catch exceptions with your own try/catch.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueFalse

Outputs

Microsoft.SqlServer.Management.Smo.Property

Returns one Property object per user option configured at the instance level, representing the default user options that apply to new database connections.

Default display properties (via Select-DefaultView):

  • ComputerName: The computer name of the SQL Server instance

  • InstanceName: The SQL Server instance name

  • SqlInstance: The full SQL Server instance name (computer\instance)

  • Name: The name of the user option (e.g., ANSI_NULLS, QUOTED_IDENTIFIER, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, CURSOR_CLOSE_ON_COMMIT, NUMERIC_ROUNDABORT, IMPLICIT_TRANSACTIONS)

  • Value: The current value of the user option (typically ON or OFF for boolean options, or a numeric value) All properties from the base SMO Property object are accessible using Select-Object *.