Export (0) Print
Expand All

Add-OdbcDsn

Windows Server 2012 R2 and Windows 8.1

Updated: June 5, 2014

Applies To: Windows 8.1, Windows PowerShell 4.0, Windows Server 2012 R2

Add-OdbcDsn

Adds an ODBC DSN.

Syntax

Parameter Set: Add0
Add-OdbcDsn [-Name] <String> -DriverName <String> -DsnType <String> [-AsJob] [-CimSession <CimSession> ] [-PassThru] [-Platform <String> ] [-SetPropertyValue <String> ] [-ThrottleLimit <Int32> ] [ <CommonParameters>]




Detailed Description

The Add-OdbcDsn cmdlet adds an Open Database Connectivity (ODBC) data source name (DSN) to the computer. You can specify the properties of the DSN by using the SetPropertyValue parameter.

Do not use the Set-OdbcDsn cmdlet to add a new DSN.

For more information about ODBC, data source names, and drivers, see Microsoft Open Database Connectivity (ODBC) (http://msdn.microsoft.com/en-us/library/ms710252.aspx), Data Sources (http://msdn.microsoft.com/en-us/library/ms711688.aspx), and Drivers (http://msdn.microsoft.com/en-us/library/ms715383.aspx) on the Microsoft Developer Network.

Parameters

-Name<String>

Specifies the name of an ODBC DSN. This cmdlet creates a DSN that has the name that this parameter specifies.


Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-DsnType<String>

Specifies the type of an ODBC DSN. This cmdlet adds a DSN of the type that this parameter specifies. The acceptable values for this parameter are: 

-- User
-- System


Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-Platform<String>

Specifies the platform architecture. This cmdlet adds an ODBC DSN that belongs to the platform that this parameter specifies. The acceptable values for this parameter are: 

-- 32-bit
-- 64-bit

The default value is 32-bit on a 32-bit process. The default value is 64-bit on a 64-bit process. If you run this cmdlet in a remote CIM session, this parameter refers to the platform architecture on the remote computer.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-DriverName<String>

Specifies the name of a driver. This cmdlet assigns the new ODBC DSN to the driver that this parameter specifies.


Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-SetPropertyValue<String>

Specifies an array of property values. This cmdlet specifies these property values for the ODBC DSN. Specify an array of strings of the form <key>=<value>.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-PassThru

Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-AsJob

Runs the cmdlet as a background job. Use this parameter to run commands that take a long time to complete. The cmdlet immediately returns an object that represents the job and then displays the command prompt. You can continue to work in the session while the job completes. To manage the job, use the *-Job cmdlets. To get the job results, use the Receive-Job cmdlet. For more information about Windows PowerShell® background jobs, see about_Jobs.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-CimSession<CimSession>

Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession or Get-CimSession cmdlet. The default is the current session on the local computer.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ThrottleLimit<Int32>

Specifies the maximum number of concurrent operations that can be established to run the cmdlet. If this parameter is omitted or a value of 0 is entered, then Windows PowerShell® calculates an optimum throttle limit for the cmdlet based on the number of CIM cmdlets that are running on the computer. The throttle limit applies only to the current cmdlet, not to the session or to the computer.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see    about_CommonParameters.

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

Outputs

The output type is the type of the objects that the cmdlet emits.

  • Microsoft.Management.Infrastructure.CimInstance#MSFT_OdbcDsn[]

Examples

Example 1: Add a 32-bit ODBC User DSN

This command adds a 32-bit ODBC User DSN named MyPayroll that uses the specified 32-bit driver with the specified properties.


PS C:\> Add-OdbcDsn -Name "MyPayroll" -DriverName "Microsoft Access Driver (*.mdb, *.accdb)" -DsnType "User" -Platform "32-bit" -SetPropertyValue 'Dbq=C:\mydatabase.accdb'

Example 2: Add an ODBC System DSN

This command adds the ODBC System DSNs named MyPayroll that use SQL Server Native Client 10.0 with the specified DSN properties. Because the command does not include the Platform parameter, the platform architecture is the default, native platform.


PS C:\> Add-OdbcDsn -Name "MyPayroll" -DriverName "SQL Server Native Client 10.0" -DsnType "System" -SetPropertyValue @("Server=MyServer", "Trusted_Connection=Yes", "Database=Payroll")

Example 3: Add and store an ODBC System DSN

This command adds the ODBC System DSNs named MyPayroll that use SQL Server Native Client 10.0 with the specified DSN properties, and then stores the results in the $newDsn variable. The command includes the PassThru parameter. Without PassThru, the cmdlet does not return anything.


PS C:\> $newDsn = Add-OdbcDsn -Name "MyPayroll" -DriverName "SQL Server Native Client 10.0" -DsnType "System" -SetPropertyValue @("Server=MyServer", "Trusted_Connection=Yes", "Database=Payroll") -PassThru

Example 4: Migrates DSNs to a newer version of a driver

This example migrates DSNs using the SQL Server Native Client 10.0 driver to a newer version of that driver. This command works for the SQL Server Native Client ODBC driver.


PS C:\> $dsnArr = Get-OdbcDsn -DriverName 'SQL Server Native Client 10.0'
PS C:\> foreach ($dsn in $dsnArr) {
          Remove-OdbcDsn -InputObject $dsn 
          # You can change the property array as well, 
          # if DSN attributes have been changed in the new driver version

          Add-OdbcDsn -Name $dsn.Name -DsnType $dsn.DsnType -Platform $dsn.Platform -DriverName 'SQL Server Native Client 12.0' -SetPropertyValue $dsn.PropertyValue
}

Related topics

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft